Merge pull request #2 from franksinankaya/frkaya/timeouts
Add connection timeout option
This commit is contained in:
Коммит
bedec757a5
|
@ -644,17 +644,6 @@ BOOL ComContainer::RemoveHandle(std::shared_ptr<WinHttpRequestImp> &srequest, CU
|
||||||
return TRUE;
|
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()
|
void ComContainer::KickStart()
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lck(m_hAsyncEventMtx);
|
std::lock_guard<std::mutex> lck(m_hAsyncEventMtx);
|
||||||
|
@ -744,20 +733,6 @@ void WinHttpHandleContainer<T>::Register(std::shared_ptr<T> rqst)
|
||||||
m_ActiveRequests.push_back(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()
|
WinHttpSessionImp::~WinHttpSessionImp()
|
||||||
{
|
{
|
||||||
TRACE("%-35s:%-8d:%-16p sesion\n", __func__, __LINE__, (void*)this);
|
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);
|
CURL_BAILOUT_ONERROR(res, request, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2384,12 +2365,15 @@ WinHttpSetTimeouts
|
||||||
__func__, __LINE__, (void*)base, nResolveTimeout, nConnectTimeout, nSendTimeout, nReceiveTimeout);
|
__func__, __LINE__, (void*)base, nResolveTimeout, nConnectTimeout, nSendTimeout, nReceiveTimeout);
|
||||||
if ((session = dynamic_cast<WinHttpSessionImp *>(base)))
|
if ((session = dynamic_cast<WinHttpSessionImp *>(base)))
|
||||||
{
|
{
|
||||||
session->SetTimeout(nReceiveTimeout);
|
session->SetReceiveTimeoutMs(nReceiveTimeout);
|
||||||
|
session->SetConnectionTimeoutMs(nConnectTimeout);
|
||||||
}
|
}
|
||||||
else if ((request = dynamic_cast<WinHttpRequestImp *>(base)))
|
else if ((request = dynamic_cast<WinHttpRequestImp *>(base)))
|
||||||
{
|
{
|
||||||
res = curl_easy_setopt(request->GetCurl(), CURLOPT_TIMEOUT_MS, nReceiveTimeout);
|
res = curl_easy_setopt(request->GetCurl(), CURLOPT_TIMEOUT_MS, nReceiveTimeout);
|
||||||
CURL_BAILOUT_ONERROR(res, request, FALSE);
|
CURL_BAILOUT_ONERROR(res, request, FALSE);
|
||||||
|
res = curl_easy_setopt(request->GetCurl(), CURLOPT_CONNECTTIMEOUT, nConnectTimeout/1000);
|
||||||
|
CURL_BAILOUT_ONERROR(res, request, FALSE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -2847,7 +2831,7 @@ WinHttpQueryOption
|
||||||
if (!session)
|
if (!session)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
*static_cast<DWORD *>(lpBuffer) = session->GetTimeout();
|
*static_cast<DWORD *>(lpBuffer) = session->GetConnectionTimeoutMs();
|
||||||
}
|
}
|
||||||
if (WINHTTP_OPTION_CALLBACK == dwOption)
|
if (WINHTTP_OPTION_CALLBACK == dwOption)
|
||||||
{
|
{
|
||||||
|
|
|
@ -68,7 +68,8 @@ class WinHttpSessionImp :public WinHttpBase
|
||||||
DWORD m_NotificationFlags = 0;
|
DWORD m_NotificationFlags = 0;
|
||||||
|
|
||||||
int m_ServerPort = 0;
|
int m_ServerPort = 0;
|
||||||
long m_Timeout = 15000;
|
long m_ReceiveTimeoutMs = 15000;
|
||||||
|
long m_ConnectionTimeoutMs = 15000;
|
||||||
BOOL m_Async = false;
|
BOOL m_Async = false;
|
||||||
|
|
||||||
bool m_closing = false;
|
bool m_closing = false;
|
||||||
|
@ -121,8 +122,11 @@ public:
|
||||||
int GetServerPort() const { return m_ServerPort; }
|
int GetServerPort() const { return m_ServerPort; }
|
||||||
void SetServerPort(int port) { m_ServerPort = port; }
|
void SetServerPort(int port) { m_ServerPort = port; }
|
||||||
|
|
||||||
long GetTimeout() const;
|
long GetReceiveTimeoutMs() const { return m_ReceiveTimeoutMs; };
|
||||||
void SetTimeout(long timeout) { m_Timeout = timeout; }
|
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; }
|
std::string &GetServerName() { return m_ServerName; }
|
||||||
|
|
||||||
|
@ -599,7 +603,6 @@ public:
|
||||||
void ResumeTransfer(CURL *handle, int bitmask);
|
void ResumeTransfer(CURL *handle, int bitmask);
|
||||||
BOOL AddHandle(std::shared_ptr<WinHttpRequestImp> &srequest, CURL *handle);
|
BOOL AddHandle(std::shared_ptr<WinHttpRequestImp> &srequest, CURL *handle);
|
||||||
BOOL RemoveHandle(std::shared_ptr<WinHttpRequestImp> &srequest, CURL *handle, bool clearPrivate);
|
BOOL RemoveHandle(std::shared_ptr<WinHttpRequestImp> &srequest, CURL *handle, bool clearPrivate);
|
||||||
long GetTimeout();
|
|
||||||
void KickStart();
|
void KickStart();
|
||||||
ComContainer();
|
ComContainer();
|
||||||
~ComContainer();
|
~ComContainer();
|
||||||
|
|
Загрузка…
Ссылка в новой задаче