mirror of https://github.com/OpenTTD/OpenTTD
Fix fdfcb09: for content service, fallback to TCP downloads when HTTP stalls (#12056)
parent
8d9fa0ea89
commit
5b3bfe4c4c
|
@ -190,7 +190,7 @@ void HttpThread()
|
||||||
|
|
||||||
/* Setup our (C-style) callback function which we pipe back into the callback. */
|
/* Setup our (C-style) callback function which we pipe back into the callback. */
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, +[](char *ptr, size_t size, size_t nmemb, void *userdata) -> size_t {
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, +[](char *ptr, size_t size, size_t nmemb, void *userdata) -> size_t {
|
||||||
Debug(net, 4, "HTTP callback: {} bytes", size * nmemb);
|
Debug(net, 6, "HTTP callback: {} bytes", size * nmemb);
|
||||||
HTTPThreadSafeCallback *callback = static_cast<HTTPThreadSafeCallback *>(userdata);
|
HTTPThreadSafeCallback *callback = static_cast<HTTPThreadSafeCallback *>(userdata);
|
||||||
|
|
||||||
/* Copy the buffer out of CURL. OnReceiveData() will free it when done. */
|
/* Copy the buffer out of CURL. OnReceiveData() will free it when done. */
|
||||||
|
|
|
@ -165,7 +165,7 @@ void NetworkHTTPRequest::WinHttpCallback(DWORD code, void *info, DWORD length)
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case WINHTTP_CALLBACK_STATUS_READ_COMPLETE:
|
case WINHTTP_CALLBACK_STATUS_READ_COMPLETE:
|
||||||
Debug(net, 4, "HTTP callback: {} bytes", length);
|
Debug(net, 6, "HTTP callback: {} bytes", length);
|
||||||
|
|
||||||
this->callback.OnReceiveData(std::unique_ptr<char[]>(static_cast<char *>(info)), length);
|
this->callback.OnReceiveData(std::unique_ptr<char[]>(static_cast<char *>(info)), length);
|
||||||
|
|
||||||
|
|
|
@ -611,8 +611,6 @@ void ClientNetworkContentSocketHandler::OnReceiveData(std::unique_ptr<char[]> da
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->lastActivity = std::chrono::steady_clock::now();
|
|
||||||
|
|
||||||
if (this->http_response_index == -1) {
|
if (this->http_response_index == -1) {
|
||||||
if (data != nullptr) {
|
if (data != nullptr) {
|
||||||
/* Append the rest of the response. */
|
/* Append the rest of the response. */
|
||||||
|
@ -799,7 +797,6 @@ void ClientNetworkContentSocketHandler::Connect()
|
||||||
*/
|
*/
|
||||||
NetworkRecvStatus ClientNetworkContentSocketHandler::CloseConnection(bool)
|
NetworkRecvStatus ClientNetworkContentSocketHandler::CloseConnection(bool)
|
||||||
{
|
{
|
||||||
this->isCancelled = true;
|
|
||||||
NetworkContentSocketHandler::CloseConnection();
|
NetworkContentSocketHandler::CloseConnection();
|
||||||
|
|
||||||
if (this->sock == INVALID_SOCKET) return NETWORK_RECV_STATUS_OKAY;
|
if (this->sock == INVALID_SOCKET) return NETWORK_RECV_STATUS_OKAY;
|
||||||
|
@ -810,6 +807,15 @@ NetworkRecvStatus ClientNetworkContentSocketHandler::CloseConnection(bool)
|
||||||
return NETWORK_RECV_STATUS_OKAY;
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cancel the current download.
|
||||||
|
*/
|
||||||
|
void ClientNetworkContentSocketHandler::Cancel(void)
|
||||||
|
{
|
||||||
|
this->isCancelled = true;
|
||||||
|
this->CloseConnection();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether we received/can send some data from/to the content server and
|
* Check whether we received/can send some data from/to the content server and
|
||||||
* when that's the case handle it appropriately
|
* when that's the case handle it appropriately
|
||||||
|
@ -818,6 +824,7 @@ void ClientNetworkContentSocketHandler::SendReceive()
|
||||||
{
|
{
|
||||||
if (this->sock == INVALID_SOCKET || this->isConnecting) return;
|
if (this->sock == INVALID_SOCKET || this->isConnecting) return;
|
||||||
|
|
||||||
|
/* Close the connection to the content server after inactivity; there can still be downloads pending via HTTP. */
|
||||||
if (std::chrono::steady_clock::now() > this->lastActivity + IDLE_TIMEOUT) {
|
if (std::chrono::steady_clock::now() > this->lastActivity + IDLE_TIMEOUT) {
|
||||||
this->CloseConnection();
|
this->CloseConnection();
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -113,6 +113,7 @@ public:
|
||||||
void Connect();
|
void Connect();
|
||||||
void SendReceive();
|
void SendReceive();
|
||||||
NetworkRecvStatus CloseConnection(bool error = true) override;
|
NetworkRecvStatus CloseConnection(bool error = true) override;
|
||||||
|
void Cancel();
|
||||||
|
|
||||||
void RequestContentList(ContentType type);
|
void RequestContentList(ContentType type);
|
||||||
void RequestContentList(uint count, const ContentID *content_ids);
|
void RequestContentList(uint count, const ContentID *content_ids);
|
||||||
|
|
|
@ -291,7 +291,7 @@ public:
|
||||||
{
|
{
|
||||||
if (widget == WID_NCDS_CANCELOK) {
|
if (widget == WID_NCDS_CANCELOK) {
|
||||||
if (this->downloaded_bytes != this->total_bytes) {
|
if (this->downloaded_bytes != this->total_bytes) {
|
||||||
_network_content_client.CloseConnection();
|
_network_content_client.Cancel();
|
||||||
this->Close();
|
this->Close();
|
||||||
} else {
|
} else {
|
||||||
/* If downloading succeeded, close the online content window. This will close
|
/* If downloading succeeded, close the online content window. This will close
|
||||||
|
|
Loading…
Reference in New Issue