From 3258c887a4e32126896efde814f549884a2ded86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Moreau?= Date: Fri, 6 Feb 2015 17:35:14 -0500 Subject: [PATCH] libfreerdp-core: add channel reconnect --- channels/drdynvc/client/drdynvc_main.c | 9 +++++---- channels/rdpgfx/client/rdpgfx_main.c | 7 ++----- libfreerdp/common/settings.c | 3 +++ libfreerdp/core/client.c | 13 ++++++++----- libfreerdp/core/client.h | 2 +- libfreerdp/core/connection.c | 6 ++++++ 6 files changed, 25 insertions(+), 15 deletions(-) diff --git a/channels/drdynvc/client/drdynvc_main.c b/channels/drdynvc/client/drdynvc_main.c index c499b928c..9b76ebb90 100644 --- a/channels/drdynvc/client/drdynvc_main.c +++ b/channels/drdynvc/client/drdynvc_main.c @@ -1083,7 +1083,7 @@ static void drdynvc_virtual_channel_event_connected(drdynvcPlugin* drdynvc, LPVO static void drdynvc_virtual_channel_event_disconnected(drdynvcPlugin* drdynvc) { - UINT rc; + UINT status; MessageQueue_PostQuit(drdynvc->queue, 0); WaitForSingleObject(drdynvc->thread, INFINITE); @@ -1094,11 +1094,12 @@ static void drdynvc_virtual_channel_event_disconnected(drdynvcPlugin* drdynvc) drdynvc->queue = NULL; drdynvc->thread = NULL; - rc = drdynvc->channelEntryPoints.pVirtualChannelClose(drdynvc->OpenHandle); - if (CHANNEL_RC_OK != rc) + status = drdynvc->channelEntryPoints.pVirtualChannelClose(drdynvc->OpenHandle); + + if (status != CHANNEL_RC_OK) { WLog_ERR(TAG, "pVirtualChannelClose failed with %s [%08X]", - WTSErrorToString(rc), rc); + WTSErrorToString(status), status); } if (drdynvc->data_in) diff --git a/channels/rdpgfx/client/rdpgfx_main.c b/channels/rdpgfx/client/rdpgfx_main.c index 8e98a6f2c..875a84a8e 100644 --- a/channels/rdpgfx/client/rdpgfx_main.c +++ b/channels/rdpgfx/client/rdpgfx_main.c @@ -22,9 +22,6 @@ #endif #include -#include -#include -#include #include #include @@ -1131,8 +1128,8 @@ int DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints) if (!gfx->zgfx) { - free (gfx); - free (context); + free(gfx); + free(context); return -1; } diff --git a/libfreerdp/common/settings.c b/libfreerdp/common/settings.c index 872581431..6c07d1514 100644 --- a/libfreerdp/common/settings.c +++ b/libfreerdp/common/settings.c @@ -503,17 +503,20 @@ ADDIN_ARGV* freerdp_dynamic_channel_clone(ADDIN_ARGV* channel) ADDIN_ARGV* _channel = NULL; _channel = (ADDIN_ARGV*) malloc(sizeof(ADDIN_ARGV)); + if (!_channel) return NULL; _channel->argc = channel->argc; _channel->argv = (char**) malloc(sizeof(char*) * channel->argc); + if (!_channel->argv) goto out_free; for (index = 0; index < _channel->argc; index++) { _channel->argv[index] = _strdup(channel->argv[index]); + if (!_channel->argv[index]) goto out_release_args; } diff --git a/libfreerdp/core/client.c b/libfreerdp/core/client.c index 111a3215e..81f5e6dfe 100644 --- a/libfreerdp/core/client.c +++ b/libfreerdp/core/client.c @@ -202,7 +202,7 @@ int freerdp_channels_post_connect(rdpChannels* channels, freerdp* instance) int hostnameLength; CHANNEL_CLIENT_DATA* pChannelClientData; - channels->is_connected = 1; + channels->connected = 1; hostname = instance->settings->ServerHostname; hostnameLength = (int) strlen(hostname); @@ -413,7 +413,10 @@ int freerdp_channels_disconnect(rdpChannels* channels, freerdp* instance) CHANNEL_OPEN_DATA* pChannelOpenData; CHANNEL_CLIENT_DATA* pChannelClientData; - channels->is_connected = 0; + if (!channels->connected) + return 0; + + channels->connected = 0; freerdp_channels_check_fds(channels, instance); /* tell all libraries we are shutting down */ @@ -498,7 +501,7 @@ UINT VCAPITYPE FreeRDP_VirtualChannelInit(LPVOID* ppInitHandle, PCHANNEL_DEF pCh if (!pChannel) return CHANNEL_RC_BAD_CHANNEL; - if (channels->is_connected) + if (channels->connected) return CHANNEL_RC_ALREADY_CONNECTED; if (versionRequested != VIRTUAL_CHANNEL_VERSION_WIN2000) @@ -571,7 +574,7 @@ UINT VCAPITYPE FreeRDP_VirtualChannelOpen(LPVOID pInitHandle, LPDWORD pOpenHandl if (!pChannelOpenEventProc) return CHANNEL_RC_BAD_PROC; - if (!channels->is_connected) + if (!channels->connected) return CHANNEL_RC_NOT_CONNECTED; pChannelOpenData = freerdp_channels_find_channel_open_data_by_name(channels, pChannelName); @@ -623,7 +626,7 @@ UINT VCAPITYPE FreeRDP_VirtualChannelWrite(DWORD openHandle, LPVOID pData, ULONG if (!channels) return CHANNEL_RC_BAD_CHANNEL_HANDLE; - if (!channels->is_connected) + if (!channels->connected) return CHANNEL_RC_NOT_CONNECTED; if (!pData) diff --git a/libfreerdp/core/client.h b/libfreerdp/core/client.h index 4d4c395f3..7a87c8f33 100644 --- a/libfreerdp/core/client.h +++ b/libfreerdp/core/client.h @@ -96,7 +96,7 @@ struct rdp_channels rdpSettings* settings; /* true once freerdp_channels_post_connect is called */ - int is_connected; + BOOL connected; /* used for locating the channels for a given instance */ freerdp* instance; diff --git a/libfreerdp/core/connection.c b/libfreerdp/core/connection.c index be201b7b0..5841b3dee 100644 --- a/libfreerdp/core/connection.c +++ b/libfreerdp/core/connection.c @@ -388,11 +388,17 @@ BOOL rdp_client_redirect(rdpRdp* rdp) BOOL rdp_client_reconnect(rdpRdp* rdp) { BOOL status; + rdpContext* context = rdp->context; + rdpChannels* channels = context->channels; + freerdp_channels_disconnect(channels, context->instance); rdp_client_disconnect(rdp); status = rdp_client_connect(rdp); + if (status) + freerdp_channels_post_connect(channels, context->instance); + return status; }