static void* rpc_client_thread(void* arg) { rdpRpc* rpc; DWORD status; DWORD nCount; HANDLE events[3]; HANDLE ReadEvent; int fd; rpc = (rdpRpc*) arg; fd = BIO_get_fd(rpc->TlsOut->bio, NULL); ReadEvent = CreateFileDescriptorEvent(NULL, TRUE, FALSE, fd); nCount = 0; events[nCount++] = rpc->client->StopEvent; events[nCount++] = Queue_Event(rpc->client->SendQueue); events[nCount++] = ReadEvent; /* Do a first free run in case some bytes were set from the HTTP headers. * We also have to do it because most of the time the underlying socket has notified, * and the ssl layer has eaten all bytes, so we won't be notified any more even if the * bytes are buffered locally */ if (rpc_client_on_read_event(rpc) < 0) { WLog_ERR(TAG, "an error occured when treating first packet"); goto out; } while (rpc->transport->layer != TRANSPORT_LAYER_CLOSED) { status = WaitForMultipleObjects(nCount, events, FALSE, 100); if (status == WAIT_TIMEOUT) continue; if (WaitForSingleObject(rpc->client->StopEvent, 0) == WAIT_OBJECT_0) break; if (WaitForSingleObject(ReadEvent, 0) == WAIT_OBJECT_0) { if (rpc_client_on_read_event(rpc) < 0) break; } if (WaitForSingleObject(Queue_Event(rpc->client->SendQueue), 0) == WAIT_OBJECT_0) { rpc_send_dequeue_pdu(rpc); } } out: CloseHandle(ReadEvent); return NULL; }
static void* rpc_client_thread(void* arg) { rdpRpc* rpc; DWORD status; DWORD nCount; HANDLE events[3]; HANDLE ReadEvent; rpc = (rdpRpc*) arg; ReadEvent = CreateFileDescriptorEvent(NULL, TRUE, FALSE, rpc->TlsOut->sockfd); nCount = 0; events[nCount++] = rpc->client->StopEvent; events[nCount++] = Queue_Event(rpc->client->SendQueue); events[nCount++] = ReadEvent; while (1) { status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE); if (WaitForSingleObject(rpc->client->StopEvent, 0) == WAIT_OBJECT_0) { break; } if (WaitForSingleObject(ReadEvent, 0) == WAIT_OBJECT_0) { if (rpc_client_on_read_event(rpc) < 0) break; } if (WaitForSingleObject(Queue_Event(rpc->client->SendQueue), 0) == WAIT_OBJECT_0) { rpc_send_dequeue_pdu(rpc); } } CloseHandle(ReadEvent); rpc_client_free(rpc); return NULL; }