Added CHANNEL_EVENT_DISCONNECTED handling.

Additional error checks and logging.
This commit is contained in:
Armin Novak 2015-01-20 11:47:47 +01:00
parent de01d7a445
commit 56cdb57452

View File

@ -50,7 +50,8 @@ int remdesk_virtual_channel_write(remdeskPlugin* remdesk, wStream* s)
if (status != CHANNEL_RC_OK)
{
WLog_ERR(TAG, "VirtualChannelWrite failed %d", status);
WLog_ERR(TAG, "VirtualChannelWrite failed with %s [%08X]",
WTSErrorToString(status), status);
return -1;
}
@ -584,7 +585,8 @@ int remdesk_send(remdeskPlugin* remdesk, wStream* s)
if (status != CHANNEL_RC_OK)
{
Stream_Free(s, TRUE);
WLog_ERR(TAG, "VirtualChannelWrite failed %d", status);
WLog_ERR(TAG, "VirtualChannelWrite failed with %s [%08X]",
WTSErrorToString(status), status);
}
return status;
@ -649,6 +651,9 @@ static VOID VCAPITYPE remdesk_virtual_channel_open_event(DWORD openHandle, UINT
case CHANNEL_EVENT_WRITE_COMPLETE:
Stream_Free((wStream*) pData, TRUE);
break;
case CHANNEL_EVENT_USER:
break;
}
}
@ -693,7 +698,8 @@ static void remdesk_virtual_channel_event_connected(remdeskPlugin* remdesk, LPVO
if (status != CHANNEL_RC_OK)
{
WLog_ERR(TAG, "open failed: status: %d", status);
WLog_ERR(TAG, "pVirtualChannelOpen failed with %s [%08X]",
WTSErrorToString(status), status);
return;
}
@ -703,22 +709,26 @@ static void remdesk_virtual_channel_event_connected(remdeskPlugin* remdesk, LPVO
(LPTHREAD_START_ROUTINE) remdesk_virtual_channel_client_thread, (void*) remdesk, 0, NULL);
}
static void remdesk_virtual_channel_event_terminated(remdeskPlugin* remdesk)
static void remdesk_virtual_channel_event_disconnected(remdeskPlugin* remdesk)
{
if (remdesk->queue)
UINT rc;
MessageQueue_PostQuit(remdesk->queue, 0);
WaitForSingleObject(remdesk->thread, INFINITE);
MessageQueue_Free(remdesk->queue);
CloseHandle(remdesk->thread);
remdesk->queue = NULL;
remdesk->thread = NULL;
rc = remdesk->channelEntryPoints.pVirtualChannelClose(remdesk->OpenHandle);
if (CHANNEL_RC_OK != rc)
{
MessageQueue_PostQuit(remdesk->queue, 0);
WaitForSingleObject(remdesk->thread, INFINITE);
MessageQueue_Free(remdesk->queue);
remdesk->queue = NULL;
CloseHandle(remdesk->thread);
remdesk->thread = NULL;
WLog_ERR(TAG, "pVirtualChannelClose failed with %s [%08X]",
WTSErrorToString(rc), rc);
}
remdesk->channelEntryPoints.pVirtualChannelClose(remdesk->OpenHandle);
if (remdesk->data_in)
{
Stream_Free(remdesk->data_in, TRUE);
@ -726,9 +736,11 @@ static void remdesk_virtual_channel_event_terminated(remdeskPlugin* remdesk)
}
remdesk_remove_open_handle_data(remdesk->OpenHandle);
remdesk_remove_init_handle_data(remdesk->InitHandle);
}
free(remdesk->context);
static void remdesk_virtual_channel_event_terminated(remdeskPlugin* remdesk)
{
remdesk_remove_init_handle_data(remdesk->InitHandle);
free(remdesk);
}
@ -752,6 +764,7 @@ static VOID VCAPITYPE remdesk_virtual_channel_init_event(LPVOID pInitHandle, UIN
break;
case CHANNEL_EVENT_DISCONNECTED:
remdesk_virtual_channel_event_disconnected(remdesk);
break;
case CHANNEL_EVENT_TERMINATED:
@ -765,6 +778,8 @@ static VOID VCAPITYPE remdesk_virtual_channel_init_event(LPVOID pInitHandle, UIN
BOOL VCAPITYPE VirtualChannelEntry(PCHANNEL_ENTRY_POINTS pEntryPoints)
{
UINT rc;
remdeskPlugin* remdesk;
RemdeskClientContext* context;
CHANNEL_ENTRY_POINTS_FREERDP* pEntryPointsEx;
@ -799,8 +814,15 @@ BOOL VCAPITYPE VirtualChannelEntry(PCHANNEL_ENTRY_POINTS pEntryPoints)
CopyMemory(&(remdesk->channelEntryPoints), pEntryPoints, sizeof(CHANNEL_ENTRY_POINTS_FREERDP));
remdesk->channelEntryPoints.pVirtualChannelInit(&remdesk->InitHandle,
rc = remdesk->channelEntryPoints.pVirtualChannelInit(&remdesk->InitHandle,
&remdesk->channelDef, 1, VIRTUAL_CHANNEL_VERSION_WIN2000, remdesk_virtual_channel_init_event);
if (CHANNEL_RC_OK != rc)
{
WLog_ERR(TAG, "pVirtualChannelInit failed with %s [%08X]",
WTSErrorToString(rc), rc);
free(remdesk);
return -1;
}
remdesk->channelEntryPoints.pInterface = *(remdesk->channelEntryPoints.ppInterface);
remdesk->channelEntryPoints.ppInterface = &(remdesk->channelEntryPoints.pInterface);