summaryrefslogtreecommitdiff
path: root/src/network/network_content.cpp
diff options
context:
space:
mode:
authorPatric Stout <truebrain@openttd.org>2021-05-13 11:46:51 +0200
committerGitHub <noreply@github.com>2021-05-13 11:46:51 +0200
commita403653805c6fd6022868c5f381e10107e1d2b20 (patch)
treeb44e4df40d65cf1fecdadab090badb73d78e0a6d /src/network/network_content.cpp
parent86741ad489c3ee2d519eeb071be846721b90412c (diff)
downloadopenttd-a403653805c6fd6022868c5f381e10107e1d2b20.tar.xz
Codechange: [Network] split CloseSocket and CloseConnection more clearly (#9261)
* Codechange: [Network] split CloseSocket and CloseConnection more clearly - CloseSocket now closes the actual OS socket. - CloseConnection frees up the resources to just before CloseSocket. - dtors call CloseSocket / CloseConnection where needed.
Diffstat (limited to 'src/network/network_content.cpp')
-rw-r--r--src/network/network_content.cpp18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/network/network_content.cpp b/src/network/network_content.cpp
index 26d220b6a..2b90cf415 100644
--- a/src/network/network_content.cpp
+++ b/src/network/network_content.cpp
@@ -76,7 +76,7 @@ bool ClientNetworkContentSocketHandler::Receive_SERVER_INFO(Packet *p)
if (!ci->IsValid()) {
delete ci;
- this->Close();
+ this->CloseConnection();
return false;
}
@@ -488,7 +488,7 @@ bool ClientNetworkContentSocketHandler::Receive_SERVER_CONTENT(Packet *p)
p->Recv_string(this->curInfo->filename, lengthof(this->curInfo->filename));
if (!this->BeforeDownload()) {
- this->Close();
+ this->CloseConnection();
return false;
}
} else {
@@ -497,7 +497,7 @@ bool ClientNetworkContentSocketHandler::Receive_SERVER_CONTENT(Packet *p)
if (toRead != 0 && (size_t)p->TransferOut(TransferOutFWrite, this->curFile) != toRead) {
DeleteWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_CONTENT_DOWNLOAD);
ShowErrorMessage(STR_CONTENT_ERROR_COULD_NOT_DOWNLOAD, STR_CONTENT_ERROR_COULD_NOT_DOWNLOAD_FILE_NOT_WRITABLE, WL_ERROR);
- this->Close();
+ this->CloseConnection();
fclose(this->curFile);
this->curFile = nullptr;
@@ -781,14 +781,16 @@ void ClientNetworkContentSocketHandler::Connect()
/**
* Disconnect from the content server.
*/
-void ClientNetworkContentSocketHandler::Close()
+NetworkRecvStatus ClientNetworkContentSocketHandler::CloseConnection(bool error)
{
- if (this->sock == INVALID_SOCKET) return;
+ NetworkContentSocketHandler::CloseConnection();
- this->CloseConnection();
- this->CloseSocket();
+ if (this->sock == INVALID_SOCKET) return NETWORK_RECV_STATUS_OKAY;
+ this->CloseSocket();
this->OnDisconnect();
+
+ return NETWORK_RECV_STATUS_OKAY;
}
/**
@@ -800,7 +802,7 @@ void ClientNetworkContentSocketHandler::SendReceive()
if (this->sock == INVALID_SOCKET || this->isConnecting) return;
if (std::chrono::steady_clock::now() > this->lastActivity + IDLE_TIMEOUT) {
- this->Close();
+ this->CloseConnection();
return;
}