From 136282dae33436bf8a109a07aa2f3df5d5a3e739 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Moreau?= Date: Mon, 26 Nov 2012 19:21:19 -0500 Subject: [PATCH] libfreerdp-utils: replace wait_obj struct with HANDLE --- channels/client/channels.c | 2 +- channels/serial/client/serial_main.c | 2 +- channels/server/channels.h | 5 +- channels/urbdrc/client/searchman.h | 2 +- channels/urbdrc/client/urbdrc_main.c | 4 +- include/freerdp/utils/thread.h | 3 +- include/freerdp/utils/wait_obj.h | 16 +++---- libfreerdp/core/transport.h | 2 +- libfreerdp/utils/wait_obj.c | 69 ++++++++-------------------- 9 files changed, 37 insertions(+), 68 deletions(-) diff --git a/channels/client/channels.c b/channels/client/channels.c index 57df2552f..dd86bb61b 100644 --- a/channels/client/channels.c +++ b/channels/client/channels.c @@ -433,7 +433,7 @@ struct rdp_channels freerdp* instance; /* signal for incoming data or event */ - struct wait_obj* signal; + HANDLE signal; /* used for sync write */ PSLIST_HEADER pSyncDataList; diff --git a/channels/serial/client/serial_main.c b/channels/serial/client/serial_main.c index a76e8b810..526829de1 100644 --- a/channels/serial/client/serial_main.c +++ b/channels/serial/client/serial_main.c @@ -62,7 +62,7 @@ struct _SERIAL_DEVICE LIST* irp_list; LIST* pending_irps; freerdp_thread* thread; - struct wait_obj* in_event; + HANDLE in_event; fd_set read_fds; fd_set write_fds; diff --git a/channels/server/channels.h b/channels/server/channels.h index 213ddc101..b2485e948 100644 --- a/channels/server/channels.h +++ b/channels/server/channels.h @@ -58,6 +58,7 @@ enum }; typedef struct rdp_peer_channel rdpPeerChannel; + struct rdp_peer_channel { WTSVirtualChannelManager* vcm; @@ -67,7 +68,7 @@ struct rdp_peer_channel UINT16 index; STREAM* receive_data; - struct wait_obj* receive_event; + HANDLE receive_event; LIST* receive_queue; HANDLE mutex; @@ -78,7 +79,7 @@ struct rdp_peer_channel struct WTSVirtualChannelManager { freerdp_peer* client; - struct wait_obj* send_event; + HANDLE send_event; LIST* send_queue; HANDLE mutex; diff --git a/channels/urbdrc/client/searchman.h b/channels/urbdrc/client/searchman.h index c6d20c511..836696321 100644 --- a/channels/urbdrc/client/searchman.h +++ b/channels/urbdrc/client/searchman.h @@ -44,7 +44,7 @@ struct _USB_SEARCHMAN USB_SEARCHDEV * tail; /* tail device in linked list */ pthread_mutex_t mutex; - struct wait_obj * term_event; + HANDLE term_event; sem_t sem_term; int strated; diff --git a/channels/urbdrc/client/urbdrc_main.c b/channels/urbdrc/client/urbdrc_main.c index 20974ce70..fa181043b 100644 --- a/channels/urbdrc/client/urbdrc_main.c +++ b/channels/urbdrc/client/urbdrc_main.c @@ -444,8 +444,8 @@ static void* urbdrc_search_usb_device(void* arg) IWTSVirtualChannel* dvc_channel; USB_SEARCHDEV* sdev; IUDEVICE* pdev = NULL; - struct wait_obj* listobj[2]; - struct wait_obj* mon_fd; + HANDLE listobj[2]; + HANDLE mon_fd; int numobj, timeout; int busnum, devnum; int success = 0, error, on_close = 0, found = 0; diff --git a/include/freerdp/utils/thread.h b/include/freerdp/utils/thread.h index d8af74021..ef92627ce 100644 --- a/include/freerdp/utils/thread.h +++ b/include/freerdp/utils/thread.h @@ -23,6 +23,7 @@ #include #include #include + #ifndef _WIN32 #include #endif @@ -35,7 +36,7 @@ struct _freerdp_thread { HANDLE mutex; - struct wait_obj* signals[5]; + HANDLE signals[5]; int num_signals; int status; diff --git a/include/freerdp/utils/wait_obj.h b/include/freerdp/utils/wait_obj.h index 5bd8e3d5a..8807dd66d 100644 --- a/include/freerdp/utils/wait_obj.h +++ b/include/freerdp/utils/wait_obj.h @@ -22,13 +22,13 @@ #include -FREERDP_API struct wait_obj* wait_obj_new(void); -FREERDP_API struct wait_obj* wait_obj_new_with_fd(void* fd); -FREERDP_API void wait_obj_free(struct wait_obj* obj); -FREERDP_API int wait_obj_is_set(struct wait_obj* obj); -FREERDP_API void wait_obj_set(struct wait_obj* obj); -FREERDP_API void wait_obj_clear(struct wait_obj* obj); -FREERDP_API int wait_obj_select(struct wait_obj** listobj, int numobj, int timeout); -FREERDP_API void wait_obj_get_fds(struct wait_obj* obj, void** fds, int* count); +FREERDP_API HANDLE wait_obj_new(void); +FREERDP_API HANDLE wait_obj_new_with_fd(void* fd); +FREERDP_API void wait_obj_free(HANDLE event); +FREERDP_API int wait_obj_is_set(HANDLE event); +FREERDP_API void wait_obj_set(HANDLE event); +FREERDP_API void wait_obj_clear(HANDLE event); +FREERDP_API int wait_obj_select(HANDLE* events, int count, int timeout); +FREERDP_API void wait_obj_get_fds(HANDLE event, void** fds, int* count); #endif diff --git a/libfreerdp/core/transport.h b/libfreerdp/core/transport.h index e61b53933..2bab8d4ef 100644 --- a/libfreerdp/core/transport.h +++ b/libfreerdp/core/transport.h @@ -61,7 +61,7 @@ struct rdp_transport void* recv_extra; STREAM* recv_buffer; TransportRecv recv_callback; - struct wait_obj* recv_event; + HANDLE recv_event; BOOL blocking; BOOL ProcessSinglePdu; BOOL SplitInputOutput; diff --git a/libfreerdp/utils/wait_obj.c b/libfreerdp/utils/wait_obj.c index 5407011fe..4bf4c8e8d 100644 --- a/libfreerdp/utils/wait_obj.c +++ b/libfreerdp/utils/wait_obj.c @@ -39,82 +39,49 @@ #include #endif -struct wait_obj +HANDLE wait_obj_new(void) { - HANDLE event; -}; - -struct wait_obj* wait_obj_new(void) -{ - struct wait_obj* obj; - - obj = (struct wait_obj*) malloc(sizeof(struct wait_obj)); - ZeroMemory(obj, sizeof(struct wait_obj)); - - obj->event = CreateEvent(NULL, TRUE, FALSE, NULL); - - return obj; + return CreateEvent(NULL, TRUE, FALSE, NULL); } -struct wait_obj* wait_obj_new_with_fd(void* fd) +HANDLE wait_obj_new_with_fd(void* fd) { - struct wait_obj* obj; - - obj = (struct wait_obj*) malloc(sizeof(struct wait_obj)); - ZeroMemory(obj, sizeof(struct wait_obj)); - - obj->event = CreateFileDescriptorEvent(NULL, TRUE, FALSE, ((int) (long) fd)); - - return obj; + return CreateFileDescriptorEvent(NULL, TRUE, FALSE, ((int) (long) fd)); } -void wait_obj_free(struct wait_obj* obj) +void wait_obj_free(HANDLE event) { - CloseHandle(obj->event); + CloseHandle(event); } -int wait_obj_is_set(struct wait_obj* obj) +int wait_obj_is_set(HANDLE event) { - return (WaitForSingleObject(obj->event, 0) == WAIT_OBJECT_0); + return (WaitForSingleObject(event, 0) == WAIT_OBJECT_0); } -void wait_obj_set(struct wait_obj* obj) +void wait_obj_set(HANDLE event) { - SetEvent(obj->event); + SetEvent(event); } -void wait_obj_clear(struct wait_obj* obj) +void wait_obj_clear(HANDLE event) { - ResetEvent(obj->event); + ResetEvent(event); } -int wait_obj_select(struct wait_obj** listobj, int numobj, int timeout) +int wait_obj_select(HANDLE* events, int count, int timeout) { - int index; - int status; - HANDLE* handles; + if (WaitForMultipleObjects(count, events, FALSE, timeout) == WAIT_FAILED) + return -1; - handles = (HANDLE*) malloc(sizeof(HANDLE) * (numobj + 1)); - ZeroMemory(handles, sizeof(HANDLE) * (numobj + 1)); - - for (index = 0; index < numobj; index++) - handles[index] = listobj[index]->event; - - if (WaitForMultipleObjects(numobj, handles, FALSE, timeout) == WAIT_FAILED) - status = -1; - else - status = 0; - - free(handles); - - return status; + return 0; } -void wait_obj_get_fds(struct wait_obj* obj, void** fds, int* count) +void wait_obj_get_fds(HANDLE event, void** fds, int* count) { int fd; - fd = GetEventFileDescriptor(obj->event); + fd = GetEventFileDescriptor(event); if (fd == -1) return;