重构MultiplexManager,使用字符串ID替代uint32_t,优化TCPClient和TCPServer的客户端管理
This commit is contained in:
@@ -6,13 +6,16 @@
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <functional>
|
||||
#include "../multiplex/multiplex_manager.h"
|
||||
|
||||
using boost::asio::ip::tcp;
|
||||
|
||||
class SteamNetworkingManager;
|
||||
|
||||
// TCP Client class
|
||||
class TCPClient {
|
||||
public:
|
||||
TCPClient(const std::string& host, int port);
|
||||
TCPClient(const std::string& host, int port, SteamNetworkingManager* manager);
|
||||
~TCPClient();
|
||||
|
||||
bool connect();
|
||||
@@ -22,10 +25,11 @@ public:
|
||||
void setReceiveCallback(std::function<void(const std::string&)> callback);
|
||||
void setReceiveCallback(std::function<void(const char*, size_t)> callback);
|
||||
void setDisconnectCallback(std::function<void()> callback);
|
||||
MultiplexManager* getMultiplexManager() { return multiplexManager_.get(); }
|
||||
|
||||
private:
|
||||
void start_read();
|
||||
void handle_read(const boost::system::error_code& error, std::size_t bytes_transferred);
|
||||
void start_read(std::string id);
|
||||
void handle_read(std::string id, const boost::system::error_code& error, std::size_t bytes_transferred);
|
||||
|
||||
std::string host_;
|
||||
int port_;
|
||||
@@ -40,4 +44,6 @@ private:
|
||||
std::function<void(const char*, size_t)> receiveCallbackBytes_;
|
||||
std::function<void()> disconnectCallback_;
|
||||
std::vector<char> buffer_;
|
||||
SteamNetworkingManager* manager_;
|
||||
std::unique_ptr<MultiplexManager> multiplexManager_;
|
||||
};
|
||||
Reference in New Issue
Block a user