From 05e6157d296639c133fcecfba150cec74bd64f82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Moreau?= Date: Wed, 19 Dec 2012 12:16:39 -0500 Subject: [PATCH] libfreerdp-core: return proper event handles on Windows --- channels/client/channels.c | 8 ++++---- channels/server/channels.c | 22 +++++++++++----------- libfreerdp/core/transport.c | 8 ++++---- winpr/include/winpr/synch.h | 5 +++-- winpr/libwinpr/synch/event.c | 28 ++++++++++++++++++++++++++++ 5 files changed, 50 insertions(+), 21 deletions(-) diff --git a/channels/client/channels.c b/channels/client/channels.c index 9950efb15..2d63d411c 100644 --- a/channels/client/channels.c +++ b/channels/client/channels.c @@ -1263,13 +1263,13 @@ static void freerdp_channels_process_sync(rdpChannels* channels, freerdp* instan BOOL freerdp_channels_get_fds(rdpChannels* channels, freerdp* instance, void** read_fds, int* read_count, void** write_fds, int* write_count) { - int fd; + void* pfd; - fd = GetEventFileDescriptor(channels->signal); + pfd = GetEventWaitObject(channels->signal); - if (fd != -1) + if (pfd) { - read_fds[*read_count] = ((void*) (long) fd); + read_fds[*read_count] = pfd; (*read_count)++; } diff --git a/channels/server/channels.c b/channels/server/channels.c index 1668a8160..5f9865c78 100644 --- a/channels/server/channels.c +++ b/channels/server/channels.c @@ -469,23 +469,23 @@ void WTSDestroyVirtualChannelManager(WTSVirtualChannelManager* vcm) void WTSVirtualChannelManagerGetFileDescriptor(WTSVirtualChannelManager* vcm, void** fds, int* fds_count) { - int fd; + void* fd; - fd = GetEventFileDescriptor(vcm->send_event); + fd = GetEventWaitObject(vcm->send_event); - if (fd != -1) + if (fd) { - fds[*fds_count] = ((void*) (long) fd); + fds[*fds_count] = fd; (*fds_count)++; } if (vcm->drdynvc_channel) { - fd = GetEventFileDescriptor(vcm->drdynvc_channel->receive_event); + fd = GetEventWaitObject(vcm->drdynvc_channel->receive_event); - if (fd != -1) + if (fd) { - fds[*fds_count] = ((void*) (long) fd); + fds[*fds_count] = fd; (*fds_count)++; } } @@ -626,7 +626,7 @@ BOOL WTSVirtualChannelQuery( /* __out */ void** ppBuffer, /* __out */ UINT32* pBytesReturned) { - int fd; + void* pfd; BOOL bval; void* fds[10]; int fds_count = 0; @@ -637,11 +637,11 @@ BOOL WTSVirtualChannelQuery( { case WTSVirtualFileHandle: - fd = GetEventFileDescriptor(channel->receive_event); + pfd = GetEventWaitObject(channel->receive_event); - if (fd != -1) + if (pfd) { - fds[fds_count] = ((void*) (long) fd); + fds[fds_count] = pfd; (fds_count)++; } diff --git a/libfreerdp/core/transport.c b/libfreerdp/core/transport.c index a1e3fae72..6b674439a 100644 --- a/libfreerdp/core/transport.c +++ b/libfreerdp/core/transport.c @@ -512,7 +512,7 @@ int transport_write(rdpTransport* transport, STREAM* s) void transport_get_fds(rdpTransport* transport, void** rfds, int* rcount) { - int fd; + void* pfd; #ifdef _WIN32 rfds[*rcount] = transport->TcpIn->wsa_event; @@ -534,11 +534,11 @@ void transport_get_fds(rdpTransport* transport, void** rfds, int* rcount) } #endif - fd = GetEventFileDescriptor(transport->recv_event); + pfd = GetEventWaitObject(transport->recv_event); - if (fd != -1) + if (pfd) { - rfds[*rcount] = ((void*) (long) fd); + rfds[*rcount] = pfd; (*rcount)++; } } diff --git a/winpr/include/winpr/synch.h b/winpr/include/winpr/synch.h index 9a067547d..02ecb8e95 100644 --- a/winpr/include/winpr/synch.h +++ b/winpr/include/winpr/synch.h @@ -259,13 +259,14 @@ WINPR_API HANDLE CreateFileDescriptorEventW(LPSECURITY_ATTRIBUTES lpEventAttribu WINPR_API HANDLE CreateFileDescriptorEventA(LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL bManualReset, BOOL bInitialState, int FileDescriptor); -WINPR_API int GetEventFileDescriptor(HANDLE hEvent); - #ifdef UNICODE #define CreateFileDescriptorEvent CreateFileDescriptorEventW #else #define CreateFileDescriptorEvent CreateFileDescriptorEventA #endif +WINPR_API int GetEventFileDescriptor(HANDLE hEvent); +WINPR_API void* GetEventWaitObject(HANDLE hEvent); + #endif /* WINPR_SYNCH_H */ diff --git a/winpr/libwinpr/synch/event.c b/winpr/libwinpr/synch/event.c index 404726568..ac4608386 100644 --- a/winpr/libwinpr/synch/event.c +++ b/winpr/libwinpr/synch/event.c @@ -201,6 +201,11 @@ HANDLE CreateFileDescriptorEventA(LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL return CreateFileDescriptorEventW(lpEventAttributes, bManualReset, bInitialState, FileDescriptor); } +/* + * Returns inner file descriptor for usage with select() + * This file descriptor is not usable on Windows + */ + int GetEventFileDescriptor(HANDLE hEvent) { #ifndef _WIN32 @@ -218,3 +223,26 @@ int GetEventFileDescriptor(HANDLE hEvent) return -1; #endif } + +/** + * Returns platform-specific wait object as a void pointer + * + * On Windows, the returned object is the same as the hEvent + * argument and is an event HANDLE usable in WaitForMultipleObjects + * + * On other platforms, the returned object can be cast to an int + * to obtain a file descriptor usable in select() + */ + +void* GetEventWaitObject(HANDLE hEvent) +{ +#ifndef _WIN32 + int fd; + + fd = GetEventFileDescriptor(hEvent); + + return ((void*) (long) fd); +#else + return hEvent; +#endif +}