Merge pull request #2611 from nfedera/fix-async-transport-thread

transport: fixed multiple errors in async thread
This commit is contained in:
Hardening 2015-05-13 08:24:35 +02:00
commit f219d341f1
1 changed files with 39 additions and 16 deletions

View File

@ -873,6 +873,7 @@ BOOL transport_disconnect(rdpTransport* transport)
static void* transport_client_thread(void* arg)
{
DWORD dwExitCode = 0;
DWORD status;
DWORD nCount;
HANDLE handles[64];
@ -880,7 +881,7 @@ static void* transport_client_thread(void* arg)
rdpContext* context = transport->context;
rdpRdp* rdp = context->rdp;
WLog_DBG(TAG, "Starting transport thread");
WLog_DBG(TAG, "Asynchronous transport thread started");
nCount = 0;
handles[nCount++] = transport->stopEvent;
@ -888,26 +889,32 @@ static void* transport_client_thread(void* arg)
status = WaitForMultipleObjects(nCount, handles, FALSE, INFINITE);
if (WaitForSingleObject(transport->stopEvent, 0) == WAIT_OBJECT_0)
switch (status)
{
WLog_DBG(TAG, "Terminating transport thread");
ExitThread(0);
return NULL;
}
case WAIT_OBJECT_0:
WLog_DBG(TAG, "stopEvent triggered");
goto out;
WLog_DBG(TAG, "Asynchronous transport activated");
case WAIT_OBJECT_0 + 1:
WLog_DBG(TAG, "connectedEvent event triggered");
break;
default:
WLog_ERR(TAG, "WaitForMultipleObjects failed with status 0x%08X", status);
dwExitCode = 1;
goto out;
}
while (1)
{
nCount = freerdp_get_event_handles(context, &handles[nCount], 64);
handles[0] = transport->stopEvent;
if (nCount == 0)
if (!(nCount = freerdp_get_event_handles(context, &handles[1], 63)))
{
WLog_ERR(TAG, "freerdp_get_event_handles failed");
break;
}
handles[nCount++] = transport->stopEvent;
nCount++;
status = WaitForMultipleObjects(nCount, handles, FALSE, INFINITE);
@ -917,10 +924,12 @@ static void* transport_client_thread(void* arg)
break;
}
if (WaitForSingleObject(transport->stopEvent, 0) == WAIT_OBJECT_0)
break;
if (WaitForMultipleObjects(nCount - 1, &handles[1], FALSE, 0) != WAIT_TIMEOUT)
if (status == WAIT_OBJECT_0)
{
WLog_DBG(TAG, "stopEvent triggered");
break;
}
else if (status > WAIT_OBJECT_0 && status < (WAIT_OBJECT_0 + nCount))
{
if (!freerdp_check_event_handles(context))
{
@ -928,10 +937,24 @@ static void* transport_client_thread(void* arg)
break;
}
}
else
{
if (status == WAIT_TIMEOUT)
{
/* This happens quite frequently although we've specified an INFINITE timeout
* WaitForMultipleObjects bug ?
*/
continue;
}
WLog_ERR(TAG, "WaitForMultipleObjects failed with status 0x%08X", status);
dwExitCode = 1;
break;
}
}
out:
WLog_DBG(TAG, "Terminating transport thread");
ExitThread(0);
ExitThread(dwExitCode);
return NULL;
}