diff --git a/include/freerdp/channels/wtsvc.h b/include/freerdp/channels/wtsvc.h index 31763dcc5..9626c5852 100644 --- a/include/freerdp/channels/wtsvc.h +++ b/include/freerdp/channels/wtsvc.h @@ -59,6 +59,7 @@ extern "C" FREERDP_API void WTSVirtualChannelManagerGetFileDescriptor(HANDLE hServer, void** fds, int* fds_count); FREERDP_API BOOL WTSVirtualChannelManagerCheckFileDescriptor(HANDLE hServer); + FREERDP_API BOOL WTSVirtualChannelManagerCheckFileDescriptorEx(HANDLE hServer, BOOL autoOpen); FREERDP_API HANDLE WTSVirtualChannelManagerGetEventHandle(HANDLE hServer); FREERDP_API BOOL WTSVirtualChannelManagerIsChannelJoined(HANDLE hServer, const char* name); FREERDP_API BYTE WTSVirtualChannelManagerGetDrdynvcState(HANDLE hServer); diff --git a/libfreerdp/core/server.c b/libfreerdp/core/server.c index 39cd0e4f2..d4e73cda9 100644 --- a/libfreerdp/core/server.c +++ b/libfreerdp/core/server.c @@ -450,16 +450,16 @@ void WTSVirtualChannelManagerGetFileDescriptor(HANDLE hServer, void** fds, int* #endif } -BOOL WTSVirtualChannelManagerCheckFileDescriptor(HANDLE hServer) +static BOOL WTSVirtualChannelManagerOpen(WTSVirtualChannelManager* vcm) { - wMessage message; - BOOL status = TRUE; - rdpPeerChannel* channel; - UINT32 dynvc_caps; - WTSVirtualChannelManager* vcm = (WTSVirtualChannelManager*)hServer; + if (!vcm) + return FALSE; if ((vcm->drdynvc_state == DRDYNVC_STATE_NONE) && vcm->client->activated) { + rdpPeerChannel* channel; + UINT32 dynvc_caps; + /* Initialize drdynvc channel once and only once. */ vcm->drdynvc_state = DRDYNVC_STATE_INITIALIZED; channel = @@ -476,6 +476,26 @@ BOOL WTSVirtualChannelManagerCheckFileDescriptor(HANDLE hServer) } } + return TRUE; +} + +BOOL WTSVirtualChannelManagerCheckFileDescriptorEx(HANDLE hServer, BOOL autoOpen) +{ + wMessage message; + BOOL status = TRUE; + WTSVirtualChannelManager* vcm; + + if (!hServer || hServer == INVALID_HANDLE_VALUE) + return FALSE; + + vcm = (WTSVirtualChannelManager*)hServer; + + if (autoOpen) + { + if (!WTSVirtualChannelManagerOpen(vcm)) + return FALSE; + } + while (MessageQueue_Peek(vcm->queue, &message, TRUE)) { BYTE* buffer; @@ -499,6 +519,11 @@ BOOL WTSVirtualChannelManagerCheckFileDescriptor(HANDLE hServer) return status; } +BOOL WTSVirtualChannelManagerCheckFileDescriptor(HANDLE hServer) +{ + return WTSVirtualChannelManagerCheckFileDescriptorEx(hServer, TRUE); +} + HANDLE WTSVirtualChannelManagerGetEventHandle(HANDLE hServer) { WTSVirtualChannelManager* vcm = (WTSVirtualChannelManager*)hServer;