diff options
author | rubidium <rubidium@openttd.org> | 2010-10-15 18:42:52 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2010-10-15 18:42:52 +0000 |
commit | 7ba07d9573b7224846c183db25af43253bf5f7b9 (patch) | |
tree | 75acd4a6ab38474b6e5c758ef43de27d1f3a6117 /src/network/network_client.cpp | |
parent | 8f9ae44a6713efa41de390846b6804a0d3d3bc92 (diff) | |
download | openttd-7ba07d9573b7224846c183db25af43253bf5f7b9.tar.xz |
(svn r20929) -Codechange: make NetworkCloseClient a class method
Diffstat (limited to 'src/network/network_client.cpp')
-rw-r--r-- | src/network/network_client.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp index 619a43ebf..929d58763 100644 --- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -51,6 +51,28 @@ ClientNetworkGameSocketHandler::~ClientNetworkGameSocketHandler() ClientNetworkGameSocketHandler::my_client = NULL; } +NetworkRecvStatus ClientNetworkGameSocketHandler::CloseConnection(NetworkRecvStatus status) +{ + assert(status != NETWORK_RECV_STATUS_OKAY); + /* + * Sending a message just before leaving the game calls cs->Send_Packets. + * This might invoke this function, which means that when we close the + * connection after cs->Send_Packets we will close an already closed + * connection. This handles that case gracefully without having to make + * that code any more complex or more aware of the validity of the socket. + */ + if (this->sock == INVALID_SOCKET) return status; + + DEBUG(net, 1, "Closed client connection %d", this->client_id); + + this->Send_Packets(true); + + delete this->GetInfo(); + delete this; + + return status; +} + /** Our client's connection. */ ClientNetworkGameSocketHandler * ClientNetworkGameSocketHandler::my_client = NULL; |