diff --git a/libfreerdp/core/freerdp.c b/libfreerdp/core/freerdp.c index 6533f89a0..68b4c9569 100644 --- a/libfreerdp/core/freerdp.c +++ b/libfreerdp/core/freerdp.c @@ -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; } diff --git a/libfreerdp/core/transport.c b/libfreerdp/core/transport.c index 51f5d9108..77bac1541 100644 --- a/libfreerdp/core/transport.c +++ b/libfreerdp/core/transport.c @@ -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); diff --git a/libfreerdp/core/transport.h b/libfreerdp/core/transport.h index 831291c1b..072ca7b9f 100644 --- a/libfreerdp/core/transport.h +++ b/libfreerdp/core/transport.h @@ -70,6 +70,7 @@ struct rdp_transport BOOL blocking; BOOL SplitInputOutput; wStreamPool* ReceivePool; + HANDLE connectedEvent; HANDLE stopEvent; HANDLE thread; BOOL async;