Merge pull request #868 from llyzs/windows
Fix event handles on Windows
This commit is contained in:
commit
0e334c2131
@ -278,7 +278,7 @@ static void* audin_server_thread_func(void* arg)
|
||||
fd = *((void**) buffer);
|
||||
WTSFreeMemory(buffer);
|
||||
|
||||
thread->signals[thread->num_signals++] = CreateFileDescriptorEvent(NULL, TRUE, FALSE, ((int) (long) fd));
|
||||
thread->signals[thread->num_signals++] = CreateWaitObjectEvent(NULL, TRUE, FALSE, fd);
|
||||
}
|
||||
|
||||
/* Wait for the client to confirm that the Audio Input dynamic channel is ready */
|
||||
|
@ -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)++;
|
||||
}
|
||||
|
||||
|
@ -175,7 +175,7 @@ static void* rdpsnd_server_thread_func(void* arg)
|
||||
fd = *((void**) buffer);
|
||||
WTSFreeMemory(buffer);
|
||||
|
||||
thread->signals[thread->num_signals++] = CreateFileDescriptorEvent(NULL, TRUE, FALSE, ((int) (long) fd));
|
||||
thread->signals[thread->num_signals++] = CreateWaitObjectEvent(NULL, TRUE, FALSE, fd);
|
||||
}
|
||||
|
||||
s = stream_new(4096);
|
||||
|
@ -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)++;
|
||||
}
|
||||
|
||||
|
@ -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)++;
|
||||
}
|
||||
}
|
||||
|
@ -258,8 +258,8 @@ WINPR_API HANDLE CreateFileDescriptorEventW(LPSECURITY_ATTRIBUTES lpEventAttribu
|
||||
BOOL bManualReset, BOOL bInitialState, int FileDescriptor);
|
||||
WINPR_API HANDLE CreateFileDescriptorEventA(LPSECURITY_ATTRIBUTES lpEventAttributes,
|
||||
BOOL bManualReset, BOOL bInitialState, int FileDescriptor);
|
||||
|
||||
WINPR_API int GetEventFileDescriptor(HANDLE hEvent);
|
||||
WINPR_API HANDLE CreateWaitObjectEvent(LPSECURITY_ATTRIBUTES lpEventAttributes,
|
||||
BOOL bManualReset, BOOL bInitialState, void* pObject);
|
||||
|
||||
#ifdef UNICODE
|
||||
#define CreateFileDescriptorEvent CreateFileDescriptorEventW
|
||||
@ -267,5 +267,8 @@ WINPR_API int GetEventFileDescriptor(HANDLE hEvent);
|
||||
#define CreateFileDescriptorEvent CreateFileDescriptorEventA
|
||||
#endif
|
||||
|
||||
WINPR_API int GetEventFileDescriptor(HANDLE hEvent);
|
||||
WINPR_API void* GetEventWaitObject(HANDLE hEvent);
|
||||
|
||||
#endif /* WINPR_SYNCH_H */
|
||||
|
||||
|
@ -201,6 +201,28 @@ HANDLE CreateFileDescriptorEventA(LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL
|
||||
return CreateFileDescriptorEventW(lpEventAttributes, bManualReset, bInitialState, FileDescriptor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an event based on the handle returned by GetEventWaitObject()
|
||||
*/
|
||||
HANDLE CreateWaitObjectEvent(LPSECURITY_ATTRIBUTES lpEventAttributes,
|
||||
BOOL bManualReset, BOOL bInitialState, void* pObject)
|
||||
{
|
||||
#ifndef _WIN32
|
||||
return CreateFileDescriptorEventW(lpEventAttributes, bManualReset, bInitialState, (int) (ULONG_PTR) pObject);
|
||||
#else
|
||||
HANDLE hEvent = NULL;
|
||||
|
||||
DuplicateHandle(GetCurrentProcess(), pObject, GetCurrentProcess(), &hEvent, 0, FALSE, DUPLICATE_SAME_ACCESS);
|
||||
|
||||
return hEvent;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns inner file descriptor for usage with select()
|
||||
* This file descriptor is not usable on Windows
|
||||
*/
|
||||
|
||||
int GetEventFileDescriptor(HANDLE hEvent)
|
||||
{
|
||||
#ifndef _WIN32
|
||||
@ -218,3 +240,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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user