diff --git a/src/winhttppal.cpp b/src/winhttppal.cpp index 349d82c..4dabcda 100644 --- a/src/winhttppal.cpp +++ b/src/winhttppal.cpp @@ -644,17 +644,6 @@ BOOL ComContainer::RemoveHandle(std::shared_ptr &srequest, CU return TRUE; } -long ComContainer::GetTimeout() -{ - long curl_timeo; - - m_MultiMutex.lock(); - curl_multi_timeout(m_curlm, &curl_timeo); - m_MultiMutex.unlock(); - - return curl_timeo; -} - void ComContainer::KickStart() { std::lock_guard lck(m_hAsyncEventMtx); @@ -744,20 +733,6 @@ void WinHttpHandleContainer::Register(std::shared_ptr rqst) m_ActiveRequests.push_back(rqst); } -long WinHttpSessionImp::GetTimeout() const { - if (m_Timeout) - return m_Timeout; - - long curl_timeo; - - curl_timeo = ComContainer::GetInstance().GetTimeout(); - - if (curl_timeo < 0) - curl_timeo = 10000; - - return curl_timeo; -} - WinHttpSessionImp::~WinHttpSessionImp() { TRACE("%-35s:%-8d:%-16p sesion\n", __func__, __LINE__, (void*)this); @@ -1746,9 +1721,15 @@ WINHTTPAPI HINTERNET WINAPI WinHttpOpenRequest( } } - if (session->GetTimeout() > 0) + if (session->GetConnectionTimeoutMs() > 0) { - res = curl_easy_setopt(request->GetCurl(), CURLOPT_TIMEOUT_MS, session->GetTimeout()); + res = curl_easy_setopt(request->GetCurl(), CURLOPT_CONNECTTIMEOUT, session->GetConnectionTimeoutMs()/1000); + CURL_BAILOUT_ONERROR(res, request, NULL); + } + + if (session->GetReceiveTimeoutMs() > 0) + { + res = curl_easy_setopt(request->GetCurl(), CURLOPT_TIMEOUT_MS, session->GetReceiveTimeoutMs()); CURL_BAILOUT_ONERROR(res, request, NULL); } @@ -2384,12 +2365,15 @@ WinHttpSetTimeouts __func__, __LINE__, (void*)base, nResolveTimeout, nConnectTimeout, nSendTimeout, nReceiveTimeout); if ((session = dynamic_cast(base))) { - session->SetTimeout(nReceiveTimeout); + session->SetReceiveTimeoutMs(nReceiveTimeout); + session->SetConnectionTimeoutMs(nConnectTimeout); } else if ((request = dynamic_cast(base))) { res = curl_easy_setopt(request->GetCurl(), CURLOPT_TIMEOUT_MS, nReceiveTimeout); CURL_BAILOUT_ONERROR(res, request, FALSE); + res = curl_easy_setopt(request->GetCurl(), CURLOPT_CONNECTTIMEOUT, nConnectTimeout/1000); + CURL_BAILOUT_ONERROR(res, request, FALSE); } else return FALSE; @@ -2847,7 +2831,7 @@ WinHttpQueryOption if (!session) return FALSE; - *static_cast(lpBuffer) = session->GetTimeout(); + *static_cast(lpBuffer) = session->GetConnectionTimeoutMs(); } if (WINHTTP_OPTION_CALLBACK == dwOption) { diff --git a/src/winhttppal_imp.h b/src/winhttppal_imp.h index 2b9bbab..21f22dc 100644 --- a/src/winhttppal_imp.h +++ b/src/winhttppal_imp.h @@ -68,7 +68,8 @@ class WinHttpSessionImp :public WinHttpBase DWORD m_NotificationFlags = 0; int m_ServerPort = 0; - long m_Timeout = 15000; + long m_ReceiveTimeoutMs = 15000; + long m_ConnectionTimeoutMs = 15000; BOOL m_Async = false; bool m_closing = false; @@ -121,8 +122,11 @@ public: int GetServerPort() const { return m_ServerPort; } void SetServerPort(int port) { m_ServerPort = port; } - long GetTimeout() const; - void SetTimeout(long timeout) { m_Timeout = timeout; } + long GetReceiveTimeoutMs() const { return m_ReceiveTimeoutMs; }; + void SetReceiveTimeoutMs(long timeout) { m_ReceiveTimeoutMs = timeout; } + + long GetConnectionTimeoutMs() const { return m_ConnectionTimeoutMs; } + void SetConnectionTimeoutMs(long timeout) { m_ConnectionTimeoutMs = timeout; } std::string &GetServerName() { return m_ServerName; } @@ -599,7 +603,6 @@ public: void ResumeTransfer(CURL *handle, int bitmask); BOOL AddHandle(std::shared_ptr &srequest, CURL *handle); BOOL RemoveHandle(std::shared_ptr &srequest, CURL *handle, bool clearPrivate); - long GetTimeout(); void KickStart(); ComContainer(); ~ComContainer();