diff --git a/winpr/libwinpr/comm/comm.c b/winpr/libwinpr/comm/comm.c index 4937a8af1..1683c1f92 100644 --- a/winpr/libwinpr/comm/comm.c +++ b/winpr/libwinpr/comm/comm.c @@ -70,7 +70,6 @@ typedef struct comm_device COMM_DEVICE; static COMM_DEVICE **_CommDevices = NULL; static HANDLE_CREATOR *_CommHandleCreator = NULL; -static HANDLE_CLOSE_CB *_CommHandleCloseCb = NULL; static pthread_once_t _CommInitialized = PTHREAD_ONCE_INIT; static void _CommInit() @@ -80,7 +79,6 @@ static void _CommInit() assert(_Log == NULL); assert(_CommDevices == NULL); assert(_CommHandleCreator == NULL); - assert(_CommHandleCloseCb == NULL); _Log = WLog_Get("com.winpr.comm"); @@ -95,19 +93,9 @@ static void _CommInit() RegisterHandleCreator(_CommHandleCreator); } - _CommHandleCloseCb = (HANDLE_CLOSE_CB*)malloc(sizeof(HANDLE_CLOSE_CB)); - if (_CommHandleCloseCb) - { - _CommHandleCloseCb->IsHandled = CommIsHandled; - _CommHandleCloseCb->CloseHandle = CommCloseHandle; - - RegisterHandleCloseCb(_CommHandleCloseCb); - } - assert(_Log != NULL); assert(_CommDevices != NULL); assert(_CommHandleCreator != NULL); - assert(_CommHandleCloseCb != NULL); } @@ -1415,25 +1403,6 @@ HANDLE CommCreateFileA(LPCSTR lpDeviceName, DWORD dwDesiredAccess, DWORD dwShare } -BOOL CommIsHandled(HANDLE handle) -{ - WINPR_COMM *pComm; - - if (!CommInitialized()) - return FALSE; - - pComm = (WINPR_COMM*)handle; - - if (!pComm || pComm->Type != HANDLE_TYPE_COMM) - { - SetLastError(ERROR_INVALID_HANDLE); - return FALSE; - } - - return TRUE; -} - - BOOL CommCloseHandle(HANDLE handle) { WINPR_COMM *pComm; diff --git a/winpr/libwinpr/comm/comm.h b/winpr/libwinpr/comm/comm.h index 92bca98a0..58fab5cf6 100644 --- a/winpr/libwinpr/comm/comm.h +++ b/winpr/libwinpr/comm/comm.h @@ -89,7 +89,6 @@ typedef struct winpr_comm WINPR_COMM; void CommLog_Print(int wlog_level, char *fmt, ...); -BOOL CommIsHandled(HANDLE handle); BOOL CommCloseHandle(HANDLE handle); #endif /* _WIN32 */ diff --git a/winpr/libwinpr/handle/handle.c b/winpr/libwinpr/handle/handle.c index dd4dedaa0..2a343bc7b 100644 --- a/winpr/libwinpr/handle/handle.c +++ b/winpr/libwinpr/handle/handle.c @@ -42,82 +42,14 @@ #include "../handle/handle.h" -/* _HandleCreators is a NULL-terminated array with a maximun of HANDLE_CREATOR_MAX HANDLE_CREATOR */ -#define HANDLE_CLOSE_CB_MAX 128 -static HANDLE_CLOSE_CB **_HandleCloseCbs = NULL; - -static pthread_once_t _HandleCloseCbsInitialized = PTHREAD_ONCE_INIT; -static void _HandleCloseCbsInit() -{ - /* NB: error management to be done outside of this function */ - - assert(_HandleCloseCbs == NULL); - - _HandleCloseCbs = (HANDLE_CLOSE_CB**)calloc(HANDLE_CLOSE_CB_MAX+1, sizeof(HANDLE_CLOSE_CB*)); - - assert(_HandleCloseCbs != NULL); -} - -/** - * Returns TRUE on success, FALSE otherwise. - */ -BOOL RegisterHandleCloseCb(HANDLE_CLOSE_CB *pHandleCloseCb) -{ - int i; - - if (pthread_once(&_HandleCloseCbsInitialized, _HandleCloseCbsInit) != 0) - { - return FALSE; - } - - if (_HandleCloseCbs == NULL) - { - return FALSE; - } - - - for (i=0; iIsHandled(hObject)) - { - return close_cb->CloseHandle(hObject); - } - } - if (Type == HANDLE_TYPE_THREAD) { @@ -275,6 +207,10 @@ BOOL CloseHandle(HANDLE hObject) return TRUE; } + else if (Type == HANDLE_TYPE_COMM) + { + return CommCloseHandle(hObject); + } return FALSE; } diff --git a/winpr/libwinpr/handle/handle.h b/winpr/libwinpr/handle/handle.h index 819e7b3db..d7a18b2ff 100644 --- a/winpr/libwinpr/handle/handle.h +++ b/winpr/libwinpr/handle/handle.h @@ -65,16 +65,4 @@ static inline BOOL winpr_Handle_GetInfo(HANDLE handle, ULONG* pType, PVOID* pObj return TRUE; } - -typedef BOOL (*pcIsHandled)(HANDLE handle); -typedef BOOL (*pcCloseHandle)(HANDLE handle); - -typedef struct _HANDLE_CLOSE_CB -{ - pcIsHandled IsHandled; - pcCloseHandle CloseHandle; -} HANDLE_CLOSE_CB; - -BOOL RegisterHandleCloseCb(HANDLE_CLOSE_CB *pHandleClose); - #endif /* WINPR_HANDLE_PRIVATE_H */