From 9a7ca1743f0c74042bca4d4903f7e56fe810edce Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 16 Mar 2008 10:00:16 +0000 Subject: accumulate client sends in the gameserver, transmit bufffer at the end of the server frame --- src/core/gameserver.cc | 6 ++++++ src/core/netclient.cc | 20 ++++++++++++++++++++ src/core/netclient.h | 9 +++++++-- 3 files changed, 33 insertions(+), 2 deletions(-) (limited to 'src/core') diff --git a/src/core/gameserver.cc b/src/core/gameserver.cc index 839ed03..985fac4 100644 --- a/src/core/gameserver.cc +++ b/src/core/gameserver.cc @@ -258,6 +258,7 @@ void GameServer::frame(float seconds) entity->entity_dirty = false; } + // update player info for (std::list::iterator it = server_network->clients.begin(); it != server_network->clients.end(); it++) { NetClient *client = *it; if (client->player()->dirty()) { @@ -271,6 +272,11 @@ void GameServer::frame(float seconds) client->player()->player_dirty = false; } } + + // transmit buffered sends + for (std::list::iterator it = server_network->clients.begin(); it != server_network->clients.end(); it++) { + (*it)->transmit(); + } } else { diff --git a/src/core/netclient.cc b/src/core/netclient.cc index 7b5d554..937cf21 100644 --- a/src/core/netclient.cc +++ b/src/core/netclient.cc @@ -26,6 +26,9 @@ NetClient::NetClient(int clientfd, std::string host, int port) : client_host = host; client_port = port; + + sendq.clear(); + messageblock.clear(); } NetClient::~NetClient() @@ -87,4 +90,21 @@ void NetClient::receive() datablock.clear(); } +void NetClient::send(std::string const &msg) +{ + sendq.append(msg); +} + +void NetClient::transmit() +{ + while (sendq.size() && !error()) { + TCPClient::send(sendq.substr(0, net::FRAMESIZE-1)); + if (sendq.size() < net::FRAMESIZE) { + sendq.clear(); + } else { + sendq.erase(0, net::FRAMESIZE-1); + } + } +} + } diff --git a/src/core/netclient.h b/src/core/netclient.h index f06f7c5..23a2787 100644 --- a/src/core/netclient.h +++ b/src/core/netclient.h @@ -41,16 +41,21 @@ public: /// receive incoming data and store messages void receive(); + + /// buffer outgoing data + void send(std::string const &msg); + + /// send bufered outgoing data + void transmit(); private: std::string client_host; int client_port; Player client_player; - std::string sendq; - std::string messageblock; std::deque recvq; + std::string sendq; }; } -- cgit v1.2.3