libfreerdp-core: return proper event handles on Windows

This commit is contained in:
Marc-André Moreau 2012-12-19 12:16:39 -05:00 committed by Vic Lee
parent c8173c405d
commit 8c746976bb
5 changed files with 50 additions and 21 deletions

View File

@ -1262,13 +1262,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)++;
}

View File

@ -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)++;
}

View File

@ -515,7 +515,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;
@ -537,11 +537,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)++;
}
}

View File

@ -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 */

View File

@ -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
}