Cancel a transfer if socket poller operation fails
When using the socket poller implementation using wxEventLoopSource objects to monitor sockets, the operation wxEventLoopBase::AddSourceForFD(... can sometimes return NULL. In these cases the socket will not be monitored as needed. The only option seems to be to cancel the transfer and report a failure
This commit is contained in:
@@ -164,9 +164,10 @@ private:
|
|||||||
void ProcessTimerCallback(long);
|
void ProcessTimerCallback(long);
|
||||||
void TimeoutNotification(wxTimerEvent&);
|
void TimeoutNotification(wxTimerEvent&);
|
||||||
void ProcessTimeoutNotification();
|
void ProcessTimeoutNotification();
|
||||||
void ProcessSocketCallback(curl_socket_t, int);
|
void ProcessSocketCallback(CURL*, curl_socket_t, int);
|
||||||
void ProcessSocketPollerResult(wxThreadEvent&);
|
void ProcessSocketPollerResult(wxThreadEvent&);
|
||||||
void CheckForCompletedTransfers();
|
void CheckForCompletedTransfers();
|
||||||
|
void FailRequest(CURL*, const wxString&);
|
||||||
void StopTransfer(CURL*);
|
void StopTransfer(CURL*);
|
||||||
|
|
||||||
WX_DECLARE_HASH_MAP(CURL*, wxWebRequestCURL*, wxPointerHash, \
|
WX_DECLARE_HASH_MAP(CURL*, wxWebRequestCURL*, wxPointerHash, \
|
||||||
|
@@ -1036,11 +1036,11 @@ int wxWebSessionCURL::TimerCallback(CURLM* WXUNUSED(multi), long timeoutms,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int wxWebSessionCURL::SocketCallback(CURL* WXUNUSED(easy), curl_socket_t sock,
|
int wxWebSessionCURL::SocketCallback(CURL* curl, curl_socket_t sock, int what,
|
||||||
int what, void* userp, void* WXUNUSED(sp))
|
void* userp, void* WXUNUSED(sp))
|
||||||
{
|
{
|
||||||
wxWebSessionCURL* session = reinterpret_cast<wxWebSessionCURL*>(userp);
|
wxWebSessionCURL* session = reinterpret_cast<wxWebSessionCURL*>(userp);
|
||||||
session->ProcessSocketCallback(sock, what);
|
session->ProcessSocketCallback(curl, sock, what);
|
||||||
return CURLM_OK;
|
return CURLM_OK;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1105,7 +1105,8 @@ static int CurlPoll2SocketPoller(int what)
|
|||||||
return pollAction;
|
return pollAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxWebSessionCURL::ProcessSocketCallback(curl_socket_t s, int what)
|
void wxWebSessionCURL::ProcessSocketCallback(CURL* curl, curl_socket_t s,
|
||||||
|
int what)
|
||||||
{
|
{
|
||||||
// Have the socket poller start or stop monitoring a socket depending of
|
// Have the socket poller start or stop monitoring a socket depending of
|
||||||
// the value of what.
|
// the value of what.
|
||||||
@@ -1117,7 +1118,23 @@ void wxWebSessionCURL::ProcessSocketCallback(curl_socket_t s, int what)
|
|||||||
case CURL_POLL_OUT:
|
case CURL_POLL_OUT:
|
||||||
wxFALLTHROUGH;
|
wxFALLTHROUGH;
|
||||||
case CURL_POLL_INOUT:
|
case CURL_POLL_INOUT:
|
||||||
m_socketPoller->StartPolling(s, CurlPoll2SocketPoller(what));
|
{
|
||||||
|
int pollAction = CurlPoll2SocketPoller(what);
|
||||||
|
bool socketIsMonitored = m_socketPoller->StartPolling(s,
|
||||||
|
pollAction);
|
||||||
|
|
||||||
|
if ( !socketIsMonitored )
|
||||||
|
{
|
||||||
|
TransferSet::iterator it = m_activeTransfers.find(curl);
|
||||||
|
|
||||||
|
if ( it != m_activeTransfers.end() )
|
||||||
|
{
|
||||||
|
FailRequest(curl,
|
||||||
|
"wxWebSession failed to monitor a socket for this "
|
||||||
|
"transfer");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case CURL_POLL_REMOVE:
|
case CURL_POLL_REMOVE:
|
||||||
m_socketPoller->StopPolling(s);
|
m_socketPoller->StopPolling(s);
|
||||||
@@ -1185,6 +1202,21 @@ void wxWebSessionCURL::CheckForCompletedTransfers()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxWebSessionCURL::FailRequest(CURL* curl,const wxString& msg)
|
||||||
|
{
|
||||||
|
TransferSet::iterator it = m_activeTransfers.find(curl);
|
||||||
|
|
||||||
|
if ( it != m_activeTransfers.end() )
|
||||||
|
{
|
||||||
|
wxWebRequestCURL* request = it->second;
|
||||||
|
m_activeTransfers.erase(it);
|
||||||
|
curl_multi_remove_handle(m_handle, curl);
|
||||||
|
StopTransfer(curl);
|
||||||
|
|
||||||
|
request->SetState(wxWebRequest::State_Failed, msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void wxWebSessionCURL::StopTransfer(CURL* curl)
|
void wxWebSessionCURL::StopTransfer(CURL* curl)
|
||||||
{
|
{
|
||||||
curl_socket_t activeSocket;
|
curl_socket_t activeSocket;
|
||||||
|
Reference in New Issue
Block a user