libwinpr-synch: proper handling fd event creation on Windows.

This commit is contained in:
Vic Lee 2012-12-21 11:32:02 +08:00
parent 8c746976bb
commit 502368dd95
4 changed files with 21 additions and 2 deletions

View File

@ -278,7 +278,7 @@ static void* audin_server_thread_func(void* arg)
fd = *((void**) buffer); fd = *((void**) buffer);
WTSFreeMemory(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 */ /* Wait for the client to confirm that the Audio Input dynamic channel is ready */

View File

@ -175,7 +175,7 @@ static void* rdpsnd_server_thread_func(void* arg)
fd = *((void**) buffer); fd = *((void**) buffer);
WTSFreeMemory(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); s = stream_new(4096);

View File

@ -258,6 +258,8 @@ WINPR_API HANDLE CreateFileDescriptorEventW(LPSECURITY_ATTRIBUTES lpEventAttribu
BOOL bManualReset, BOOL bInitialState, int FileDescriptor); BOOL bManualReset, BOOL bInitialState, int FileDescriptor);
WINPR_API HANDLE CreateFileDescriptorEventA(LPSECURITY_ATTRIBUTES lpEventAttributes, WINPR_API HANDLE CreateFileDescriptorEventA(LPSECURITY_ATTRIBUTES lpEventAttributes,
BOOL bManualReset, BOOL bInitialState, int FileDescriptor); BOOL bManualReset, BOOL bInitialState, int FileDescriptor);
WINPR_API HANDLE CreateWaitObjectEvent(LPSECURITY_ATTRIBUTES lpEventAttributes,
BOOL bManualReset, BOOL bInitialState, void* pObject);
#ifdef UNICODE #ifdef UNICODE
#define CreateFileDescriptorEvent CreateFileDescriptorEventW #define CreateFileDescriptorEvent CreateFileDescriptorEventW

View File

@ -201,6 +201,23 @@ HANDLE CreateFileDescriptorEventA(LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL
return CreateFileDescriptorEventW(lpEventAttributes, bManualReset, bInitialState, FileDescriptor); 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() * Returns inner file descriptor for usage with select()
* This file descriptor is not usable on Windows * This file descriptor is not usable on Windows