libfreerdp-core: synchronize transport thread

This commit is contained in:
Marc-André Moreau 2013-04-30 18:25:18 -04:00
parent e88b59c32c
commit 8b617cd794
3 changed files with 20 additions and 9 deletions

View File

@ -73,7 +73,7 @@ BOOL freerdp_connect(freerdp* instance)
extension_load_and_init_plugins(rdp->extension);
extension_pre_connect(rdp->extension);
if (status != TRUE)
if (!status)
{
if (!connectErrorCode)
{
@ -84,6 +84,7 @@ BOOL freerdp_connect(freerdp* instance)
}
status = rdp_client_connect(rdp);
/* --authonly tests the connection without a UI */
if (instance->settings->AuthenticationOnly)
{
@ -105,7 +106,7 @@ BOOL freerdp_connect(freerdp* instance)
IFCALLRET(instance->PostConnect, status, instance);
update_post_connect(instance->update);
if (status != TRUE)
if (!status)
{
fprintf(stderr, "freerdp_post_connect failed\n");
@ -156,7 +157,9 @@ BOOL freerdp_connect(freerdp* instance)
{
connectErrorCode = UNDEFINEDCONNECTERROR;
}
SetEvent(rdp->transport->connectedEvent);
return status;
}

View File

@ -795,17 +795,20 @@ static void* transport_client_thread(void* arg)
transport = (rdpTransport*) arg;
instance = (freerdp*) transport->settings->instance;
/**
* Ugly temporary hack to start thread after connection
*/
Sleep(2000);
while (1)
{
nCount = 0;
events[nCount++] = transport->stopEvent;
events[nCount] = transport->connectedEvent;
status = WaitForMultipleObjects(nCount + 1, events, FALSE, INFINITE);
if (WaitForSingleObject(transport->stopEvent, 0) == WAIT_OBJECT_0)
{
break;
}
transport_get_read_handles(transport, (HANDLE*) &events, &nCount);
status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE);
@ -845,6 +848,8 @@ rdpTransport* transport_new(rdpSettings* settings)
transport->ReceiveBuffer = StreamPool_Take(transport->ReceivePool, 0);
transport->ReceiveEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
transport->connectedEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
/* buffers for blocking read/write */
transport->ReceiveStream = StreamPool_Take(transport->ReceivePool, 0);
transport->SendStream = stream_new(BUFFER_SIZE);
@ -872,6 +877,8 @@ void transport_free(rdpTransport* transport)
stream_free(transport->SendStream);
CloseHandle(transport->ReceiveEvent);
CloseHandle(transport->connectedEvent);
if (transport->TlsIn)
tls_free(transport->TlsIn);

View File

@ -70,6 +70,7 @@ struct rdp_transport
BOOL blocking;
BOOL SplitInputOutput;
wStreamPool* ReceivePool;
HANDLE connectedEvent;
HANDLE stopEvent;
HANDLE thread;
BOOL async;