Merge pull request #2301 from akallabeth/disconnect_fix

Disconnect / Reconnect fix
This commit is contained in:
Marc-André Moreau 2015-01-14 08:56:54 -05:00
commit 620694c10a
8 changed files with 76 additions and 71 deletions

View File

@ -716,7 +716,7 @@ BOOL xf_get_pixmap_info(xfContext* xfc)
return FALSE;
}
vi = NULL;
vi = vis;
for (i = 0; i < vi_count; i++)
{
@ -802,6 +802,7 @@ static void xf_post_disconnect(freerdp* instance)
}
xf_monitors_free(xfc, instance->settings);
gdi_free(instance);
}
static void xf_play_sound(rdpContext* context, PLAY_SOUND_UPDATE* play_sound)
@ -1657,7 +1658,6 @@ void* xf_thread(void *param)
exit_code = freerdp_error_info(instance);
freerdp_disconnect(instance);
gdi_free(instance);
ExitThread(exit_code);
return NULL;
@ -1763,6 +1763,7 @@ static int xfreerdp_client_start(rdpContext* context)
WLog_ERR(TAG, "error: server hostname was not specified with /v:<server>[:port]");
return -1;
}
xfc->disconnect = FALSE;
xfc->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) xf_thread,
context->instance, 0, NULL);
return 0;

View File

@ -289,7 +289,7 @@ BOOL rdp_client_connect(rdpRdp* rdp)
{
if (!connectErrorCode)
{
connectErrorCode = MCSCONNECTINITIALERROR;
connectErrorCode = MCSCONNECTINITIALERROR;
}
if (!freerdp_get_last_error(rdp->context))
@ -319,7 +319,18 @@ BOOL rdp_client_connect(rdpRdp* rdp)
BOOL rdp_client_disconnect(rdpRdp* rdp)
{
return transport_disconnect(rdp->transport);
BOOL rc;
if (rdp->settingsCopy)
{
freerdp_settings_free(rdp->settingsCopy);
rdp->settingsCopy = NULL;
}
rc = nego_disconnect(rdp->nego);
rdp_reset(rdp);
rdp_client_transition_to_state(rdp, CONNECTION_STATE_INITIAL);
return rc;
}
BOOL rdp_client_redirect(rdpRdp* rdp)
@ -328,9 +339,6 @@ BOOL rdp_client_redirect(rdpRdp* rdp)
rdpSettings* settings = rdp->settings;
rdp_client_disconnect(rdp);
rdp_reset(rdp);
rdp_redirection_apply_settings(rdp);
if (settings->RedirectionFlags & LB_LOAD_BALANCE_INFO)
@ -373,15 +381,6 @@ BOOL rdp_client_redirect(rdpRdp* rdp)
return status;
}
BOOL rdp_client_reconnect(rdpRdp* rdp)
{
rdp_client_disconnect(rdp);
rdp_reset(rdp);
return rdp_client_connect(rdp);
}
static BYTE fips_ivec[8] = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
static BOOL rdp_client_establish_keys(rdpRdp* rdp)
@ -758,7 +757,7 @@ BOOL rdp_client_connect_mcs_channel_join_confirm(rdpRdp* rdp, wStream* s)
return TRUE;
}
BOOL rdp_client_connect_auto_detect(rdpRdp* rdp, wStream *s)
BOOL rdp_client_connect_auto_detect(rdpRdp* rdp, wStream* s)
{
BYTE* mark;
UINT16 length;
@ -1153,7 +1152,6 @@ BOOL rdp_server_reactivate(rdpRdp* rdp)
return FALSE;
rdp->AwaitCapabilities = TRUE;
return TRUE;
}
@ -1239,7 +1237,6 @@ int rdp_server_transition_to_state(rdpRdp* rdp, int state)
* PostConnect should only be called once and should not
* be called after a reactivation sequence.
*/
IFCALLRET(client->PostConnect, client->connected, client);
if (!client->connected)

View File

@ -48,8 +48,8 @@ enum CONNECTION_STATE
};
BOOL rdp_client_connect(rdpRdp* rdp);
BOOL rdp_client_disconnect(rdpRdp* rdp);
BOOL rdp_client_redirect(rdpRdp* rdp);
BOOL rdp_client_reconnect(rdpRdp* rdp);
BOOL rdp_client_connect_mcs_connect_response(rdpRdp* rdp, wStream* s);
BOOL rdp_client_connect_mcs_attach_user_confirm(rdpRdp* rdp, wStream* s);
BOOL rdp_client_connect_mcs_channel_join_confirm(rdpRdp* rdp, wStream* s);

View File

@ -318,8 +318,7 @@ BOOL freerdp_disconnect(freerdp* instance)
rdpRdp* rdp;
rdp = instance->context->rdp;
transport_disconnect(rdp->transport);
rdp_client_disconnect(rdp);
update_post_disconnect(instance->update);
IFCALL(instance->PostDisconnect, instance);
@ -335,7 +334,8 @@ BOOL freerdp_disconnect(freerdp* instance)
BOOL freerdp_reconnect(freerdp* instance)
{
return rdp_client_reconnect(instance->context->rdp);
freerdp_disconnect(instance);
return freerdp_connect(instance);
}
BOOL freerdp_shall_disconnect(freerdp* instance)

View File

@ -63,7 +63,9 @@ static const char PROTOCOL_SECURITY_STRINGS[9][4] =
};
#endif /* WITH_DEBUG_NEGO */
BOOL nego_security_connect(rdpNego* nego);
static BOOL nego_transport_connect(rdpNego* nego);
static BOOL nego_transport_disconnect(rdpNego* nego);
static BOOL nego_security_connect(rdpNego* nego);
/**
* Negotiate protocol security and connect.
@ -190,6 +192,13 @@ BOOL nego_connect(rdpNego* nego)
return TRUE;
}
BOOL nego_disconnect(rdpNego* nego)
{
rdpSettings* settings = nego->transport->settings;
nego->state = NEGO_STATE_INITIAL;
return nego_transport_disconnect(nego);
}
/* connect to selected security layer */
BOOL nego_security_connect(rdpNego* nego)
{
@ -281,7 +290,7 @@ BOOL nego_transport_connect(rdpNego* nego)
* @return
*/
int nego_transport_disconnect(rdpNego* nego)
BOOL nego_transport_disconnect(rdpNego* nego)
{
if (nego->tcp_connected)
transport_disconnect(nego->transport);
@ -289,7 +298,7 @@ int nego_transport_disconnect(rdpNego* nego)
nego->tcp_connected = FALSE;
nego->security_connected = FALSE;
return 1;
return TRUE;
}
/**

View File

@ -118,6 +118,7 @@ struct rdp_nego
typedef struct rdp_nego rdpNego;
BOOL nego_connect(rdpNego* nego);
BOOL nego_disconnect(rdpNego* nego);
BOOL nego_send_preconnection_pdu(rdpNego* nego);
@ -137,7 +138,7 @@ void nego_process_negotiation_response(rdpNego* nego, wStream* s);
void nego_process_negotiation_failure(rdpNego* nego, wStream* s);
BOOL nego_send_negotiation_response(rdpNego* nego);
rdpNego* nego_new(struct rdp_transport * transport);
rdpNego* nego_new(struct rdp_transport* transport);
void nego_free(rdpNego* nego);
void nego_init(rdpNego* nego);

View File

@ -1439,6 +1439,10 @@ void rdp_reset(rdpRdp* rdp)
rdp->nego = nego_new(rdp->transport);
rdp->mcs = mcs_new(rdp->transport);
rdp->transport->layer = TRANSPORT_LAYER_TCP;
rdp->disconnect = FALSE;
rdp->errorInfo = 0;
rdp->deactivation_reactivation = 0;
rdp->finalize_sc_pdus = 0;
}
/**

View File

@ -102,8 +102,40 @@ BOOL transport_disconnect(rdpTransport* transport)
return FALSE;
transport_stop(transport);
BIO_free_all(transport->frontBio);
transport->frontBio = 0;
if (transport->frontBio)
{
BIO_free_all(transport->frontBio);
transport->frontBio = NULL;
}
if (transport->TlsIn)
tls_free(transport->TlsIn);
if (transport->TlsOut != transport->TlsIn)
tls_free(transport->TlsOut);
transport->TlsIn = NULL;
transport->TlsOut = NULL;
if (transport->tsg)
{
tsg_free(transport->tsg);
transport->tsg = NULL;
}
if (transport->TcpOut != transport->TcpIn)
freerdp_tcp_free(transport->TcpOut);
transport->TcpOut = NULL;
if (transport->TsgTls)
{
tls_free(transport->TsgTls);
transport->TsgTls = NULL;
}
transport->layer = TRANSPORT_LAYER_TCP;
return status;
}
@ -122,9 +154,7 @@ static int transport_bio_tsg_write(BIO* bio, const char* buf, int num)
{
int status;
rdpTsg* tsg = (rdpTsg*) bio->ptr;
BIO_clear_flags(bio, BIO_FLAGS_WRITE);
status = tsg_write(tsg, (BYTE*) buf, num);
if (status < 0)
@ -148,9 +178,7 @@ static int transport_bio_tsg_read(BIO* bio, char* buf, int size)
{
int status;
rdpTsg* tsg = (rdpTsg*) bio->ptr;
BIO_clear_flags(bio, BIO_FLAGS_READ);
status = tsg_read(tsg, (BYTE*) buf, size);
if (status < 0)
@ -365,7 +393,6 @@ BOOL transport_tsg_connect(rdpTransport* transport, const char* hostname, UINT16
rdpSettings* settings = transport->settings;
instance = (freerdp*) transport->settings->instance;
context = instance->context;
tsg = tsg_new(transport);
if (!tsg)
@ -1111,13 +1138,10 @@ static void* transport_client_thread(void* arg)
rdpTransport* transport = (rdpTransport*) arg;
rdpContext* context = transport->context;
freerdp* instance = context->instance;
WLog_Print(transport->log, WLOG_DEBUG, "Starting transport thread");
nCount = 0;
handles[nCount++] = transport->stopEvent;
handles[nCount++] = transport->connectedEvent;
status = WaitForMultipleObjects(nCount, handles, FALSE, INFINITE);
if (WaitForSingleObject(transport->stopEvent, 0) == WAIT_OBJECT_0)
@ -1161,7 +1185,6 @@ static void* transport_client_thread(void* arg)
rdpTransport* transport_new(rdpContext* context)
{
rdpTransport* transport;
transport = (rdpTransport*) calloc(1, sizeof(rdpTransport));
if (!transport)
@ -1169,7 +1192,6 @@ rdpTransport* transport_new(rdpContext* context)
transport->context = context;
transport->settings = context->settings;
WLog_Init();
transport->log = WLog_Get(TAG);
@ -1237,13 +1259,10 @@ void transport_free(rdpTransport* transport)
if (!transport)
return;
transport_stop(transport);
transport_disconnect(transport);
if (transport->tsg)
{
tsg_free(transport->tsg);
transport->tsg = NULL;
}
if (transport->TcpIn)
freerdp_tcp_free(transport->TcpIn);
if (transport->ReceiveBuffer)
Stream_Release(transport->ReceiveBuffer);
@ -1251,33 +1270,7 @@ void transport_free(rdpTransport* transport)
StreamPool_Free(transport->ReceivePool);
CloseHandle(transport->ReceiveEvent);
CloseHandle(transport->connectedEvent);
if (transport->TlsIn)
tls_free(transport->TlsIn);
if (transport->TlsOut != transport->TlsIn)
tls_free(transport->TlsOut);
transport->TlsIn = NULL;
transport->TlsOut = NULL;
if (transport->TcpIn)
freerdp_tcp_free(transport->TcpIn);
if (transport->TcpOut != transport->TcpIn)
freerdp_tcp_free(transport->TcpOut);
transport->TcpIn = NULL;
transport->TcpOut = NULL;
if (transport->TsgTls)
{
tls_free(transport->TsgTls);
transport->TsgTls = NULL;
}
DeleteCriticalSection(&(transport->ReadLock));
DeleteCriticalSection(&(transport->WriteLock));
free(transport);
}