1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-29 23:07:48 +02:00

Implemented connection handling

This commit is contained in:
Ivan Savenko
2023-11-12 13:27:22 +02:00
parent c2c43602ea
commit dff9cf39c0
11 changed files with 106 additions and 40 deletions

View File

@@ -13,7 +13,7 @@
VCMI_LIB_NAMESPACE_BEGIN
class DLL_LINKAGE NetworkConnection : boost::noncopyable
class DLL_LINKAGE NetworkConnection :public std::enable_shared_from_this<NetworkConnection>, boost::noncopyable
{
static const int messageHeaderSize = sizeof(uint32_t);
static const int messageMaxSize = 1024;
@@ -21,13 +21,14 @@ class DLL_LINKAGE NetworkConnection : boost::noncopyable
std::shared_ptr<NetworkSocket> socket;
NetworkBuffer readBuffer;
INetworkConnectionListener & listener;
void onHeaderReceived(const boost::system::error_code & ec);
void onPacketReceived(const boost::system::error_code & ec, uint32_t expectedPacketSize);
uint32_t readPacketSize(const boost::system::error_code & ec);
uint32_t readPacketSize();
public:
NetworkConnection(const std::shared_ptr<NetworkSocket> & socket);
NetworkConnection(const std::shared_ptr<NetworkSocket> & socket, INetworkConnectionListener & listener);
void start();
void sendPacket(const std::vector<uint8_t> & message);