Added CHANNEL_EVENT_DISCONNECTED handling.

Additional error checks and logging.
This commit is contained in:
Armin Novak 2015-01-20 11:55:50 +01:00
parent 4171589647
commit bbacca6db2
1 changed files with 36 additions and 18 deletions

View File

@ -55,7 +55,8 @@ int rail_send(railPlugin* rail, wStream* s)
if (status != CHANNEL_RC_OK) if (status != CHANNEL_RC_OK)
{ {
Stream_Free(s, TRUE); Stream_Free(s, TRUE);
WLog_ERR(TAG, "rail_send: VirtualChannelWrite failed %d", status); WLog_ERR(TAG, "VirtualChannelWrite failed with %s [%08X]",
WTSErrorToString(status), status);
} }
return status; return status;
@ -419,6 +420,9 @@ static VOID VCAPITYPE rail_virtual_channel_open_event(DWORD openHandle, UINT eve
case CHANNEL_EVENT_WRITE_COMPLETE: case CHANNEL_EVENT_WRITE_COMPLETE:
Stream_Free((wStream*) pData, TRUE); Stream_Free((wStream*) pData, TRUE);
break; break;
case CHANNEL_EVENT_USER:
break;
} }
} }
@ -461,7 +465,8 @@ static void rail_virtual_channel_event_connected(railPlugin* rail, LPVOID pData,
if (status != CHANNEL_RC_OK) if (status != CHANNEL_RC_OK)
{ {
WLog_ERR(TAG, "rail_virtual_channel_event_connected: open failed: status: %d", status); WLog_ERR(TAG, "pVirtualChannelOpen failed with %s [%08X]",
WTSErrorToString(status), status);
return; return;
} }
@ -471,21 +476,24 @@ static void rail_virtual_channel_event_connected(railPlugin* rail, LPVOID pData,
(LPTHREAD_START_ROUTINE) rail_virtual_channel_client_thread, (void*) rail, 0, NULL); (LPTHREAD_START_ROUTINE) rail_virtual_channel_client_thread, (void*) rail, 0, NULL);
} }
static void rail_virtual_channel_event_terminated(railPlugin* rail) static void rail_virtual_channel_event_disconnected(railPlugin* rail)
{ {
if (rail->queue) UINT rc;
{
MessageQueue_PostQuit(rail->queue, 0); MessageQueue_PostQuit(rail->queue, 0);
WaitForSingleObject(rail->thread, INFINITE); WaitForSingleObject(rail->thread, INFINITE);
MessageQueue_Free(rail->queue); MessageQueue_Free(rail->queue);
rail->queue = NULL;
CloseHandle(rail->thread); CloseHandle(rail->thread);
rail->thread = NULL;
}
rail->channelEntryPoints.pVirtualChannelClose(rail->OpenHandle); rail->queue = NULL;
rail->thread = NULL;
rc = rail->channelEntryPoints.pVirtualChannelClose(rail->OpenHandle);
if (CHANNEL_RC_OK != rc)
{
WLog_ERR(TAG, "pVirtualChannelClose failed with %s [%08X]",
WTSErrorToString(rc), rc);
}
if (rail->data_in) if (rail->data_in)
{ {
@ -494,10 +502,11 @@ static void rail_virtual_channel_event_terminated(railPlugin* rail)
} }
rail_remove_open_handle_data(rail->OpenHandle); rail_remove_open_handle_data(rail->OpenHandle);
}
static void rail_virtual_channel_event_terminated(railPlugin* rail)
{
rail_remove_init_handle_data(rail->InitHandle); rail_remove_init_handle_data(rail->InitHandle);
free(rail->context);
free(rail); free(rail);
} }
@ -520,6 +529,7 @@ static VOID VCAPITYPE rail_virtual_channel_init_event(LPVOID pInitHandle, UINT e
break; break;
case CHANNEL_EVENT_DISCONNECTED: case CHANNEL_EVENT_DISCONNECTED:
rail_virtual_channel_event_disconnected(rail);
break; break;
case CHANNEL_EVENT_TERMINATED: case CHANNEL_EVENT_TERMINATED:
@ -533,6 +543,7 @@ static VOID VCAPITYPE rail_virtual_channel_init_event(LPVOID pInitHandle, UINT e
BOOL VCAPITYPE VirtualChannelEntry(PCHANNEL_ENTRY_POINTS pEntryPoints) BOOL VCAPITYPE VirtualChannelEntry(PCHANNEL_ENTRY_POINTS pEntryPoints)
{ {
UINT rc;
railPlugin* rail; railPlugin* rail;
RailClientContext* context; RailClientContext* context;
CHANNEL_ENTRY_POINTS_FREERDP* pEntryPointsEx; CHANNEL_ENTRY_POINTS_FREERDP* pEntryPointsEx;
@ -589,8 +600,15 @@ BOOL VCAPITYPE VirtualChannelEntry(PCHANNEL_ENTRY_POINTS pEntryPoints)
CopyMemory(&(rail->channelEntryPoints), pEntryPoints, sizeof(CHANNEL_ENTRY_POINTS_FREERDP)); CopyMemory(&(rail->channelEntryPoints), pEntryPoints, sizeof(CHANNEL_ENTRY_POINTS_FREERDP));
rail->channelEntryPoints.pVirtualChannelInit(&rail->InitHandle, rc = rail->channelEntryPoints.pVirtualChannelInit(&rail->InitHandle,
&rail->channelDef, 1, VIRTUAL_CHANNEL_VERSION_WIN2000, rail_virtual_channel_init_event); &rail->channelDef, 1, VIRTUAL_CHANNEL_VERSION_WIN2000, rail_virtual_channel_init_event);
if (CHANNEL_RC_OK != rc)
{
WLog_ERR(TAG, "pVirtualChannelInit failed with %s [%08X]",
WTSErrorToString(rc), rc);
free(rail);
return -1;
}
rail->channelEntryPoints.pInterface = *(rail->channelEntryPoints.ppInterface); rail->channelEntryPoints.pInterface = *(rail->channelEntryPoints.ppInterface);
rail->channelEntryPoints.ppInterface = &(rail->channelEntryPoints.pInterface); rail->channelEntryPoints.ppInterface = &(rail->channelEntryPoints.pInterface);