From 98c4cb56a1f086070b328622c8e4093e8eafc427 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Moreau?= Date: Thu, 6 Dec 2012 16:49:50 -0500 Subject: [PATCH] libfreerdp-core: set TSG non-blocking mode --- libfreerdp/core/gateway/rpc.h | 1 - libfreerdp/core/gateway/tsg.c | 19 +++++++++++++++++++ libfreerdp/core/gateway/tsg.h | 2 ++ libfreerdp/core/transport.c | 5 +++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/libfreerdp/core/gateway/rpc.h b/libfreerdp/core/gateway/rpc.h index 4836dd85e..e8bd54f59 100644 --- a/libfreerdp/core/gateway/rpc.h +++ b/libfreerdp/core/gateway/rpc.h @@ -54,7 +54,6 @@ typedef struct typedef struct _RPC_PDU { - SLIST_ENTRY ItemEntry; BYTE* Buffer; UINT32 Size; UINT32 Length; diff --git a/libfreerdp/core/gateway/tsg.c b/libfreerdp/core/gateway/tsg.c index 5b2ec4e09..d30e162f5 100644 --- a/libfreerdp/core/gateway/tsg.c +++ b/libfreerdp/core/gateway/tsg.c @@ -1083,6 +1083,8 @@ BOOL tsg_connect(rdpTsg* tsg, const char* hostname, UINT16 port) rpc->client->SynchronousSend = TRUE; rpc->client->SynchronousReceive = TRUE; + printf("TS Gateway Connection Success\n"); + return TRUE; } @@ -1097,6 +1099,9 @@ int tsg_read(rdpTsg* tsg, BYTE* data, UINT32 length) { CopyLength = (tsg->BytesAvailable > length) ? length : tsg->BytesAvailable; + //printf("Reading from the same PDU: copy: %d length: %d avail: %d\n", + // CopyLength, length, tsg->BytesAvailable); + CopyMemory(data, &tsg->pdu->Buffer[tsg->BytesRead], CopyLength); tsg->BytesAvailable -= CopyLength; tsg->BytesRead += CopyLength; @@ -1110,6 +1115,9 @@ int tsg_read(rdpTsg* tsg, BYTE* data, UINT32 length) { tsg->pdu = rpc_recv_dequeue_pdu(rpc); + if (!tsg->pdu) + return 0; + if ((tsg->pdu->Flags & RPC_PDU_FLAG_STUB) && (tsg->pdu->Length == 4)) { DEBUG_TSG("Ignoring TsProxySetupReceivePipe Response"); @@ -1123,6 +1131,9 @@ int tsg_read(rdpTsg* tsg, BYTE* data, UINT32 length) CopyLength = (tsg->BytesAvailable > length) ? length : tsg->BytesAvailable; + //printf("Reading new PDU: copy: %d length: %d avail: %d\n", + // CopyLength, length, tsg->BytesAvailable); + CopyMemory(data, &tsg->pdu->Buffer[tsg->BytesRead], CopyLength); tsg->BytesAvailable -= CopyLength; tsg->BytesRead += CopyLength; @@ -1139,6 +1150,14 @@ int tsg_write(rdpTsg* tsg, BYTE* data, UINT32 length) return TsProxySendToServer((handle_t) tsg, data, 1, &length); } +BOOL tsg_set_blocking_mode(rdpTsg* tsg, BOOL blocking) +{ + tsg->rpc->client->SynchronousSend = TRUE; + tsg->rpc->client->SynchronousReceive = blocking; + + return TRUE; +} + rdpTsg* tsg_new(rdpTransport* transport) { rdpTsg* tsg; diff --git a/libfreerdp/core/gateway/tsg.h b/libfreerdp/core/gateway/tsg.h index 9e46f93c8..a3c365c9e 100644 --- a/libfreerdp/core/gateway/tsg.h +++ b/libfreerdp/core/gateway/tsg.h @@ -307,6 +307,8 @@ BOOL tsg_connect(rdpTsg* tsg, const char* hostname, UINT16 port); int tsg_write(rdpTsg* tsg, BYTE* data, UINT32 length); int tsg_read(rdpTsg* tsg, BYTE* data, UINT32 length); +BOOL tsg_set_blocking_mode(rdpTsg* tsg, BOOL blocking); + rdpTsg* tsg_new(rdpTransport* transport); void tsg_free(rdpTsg* tsg); diff --git a/libfreerdp/core/transport.c b/libfreerdp/core/transport.c index f89a053c5..3d1bd7fcb 100644 --- a/libfreerdp/core/transport.c +++ b/libfreerdp/core/transport.c @@ -532,6 +532,11 @@ BOOL transport_set_blocking_mode(rdpTransport* transport, BOOL blocking) status &= tcp_set_blocking_mode(transport->TcpIn, blocking); } + if (transport->layer == TRANSPORT_LAYER_TSG) + { + tsg_set_blocking_mode(transport->tsg, blocking); + } + return status; }