winpr-handle: removed RegisterHandleCloseCb() which would require a better synchronization
winpr-comm: don't use anymore RegisterHandleCloseCb()
This commit is contained in:
parent
0d54307251
commit
8f3b3fa573
@ -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;
|
||||
|
@ -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 */
|
||||
|
@ -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; i<HANDLE_CLOSE_CB_MAX; i++)
|
||||
{
|
||||
if (_HandleCloseCbs[i] == NULL)
|
||||
{
|
||||
_HandleCloseCbs[i] = pHandleCloseCb;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
BOOL CloseHandle(HANDLE hObject)
|
||||
{
|
||||
int i;
|
||||
ULONG Type;
|
||||
PVOID Object;
|
||||
|
||||
if (!winpr_Handle_GetInfo(hObject, &Type, &Object))
|
||||
return FALSE;
|
||||
|
||||
if (pthread_once(&_HandleCloseCbsInitialized, _HandleCloseCbsInit) != 0)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (_HandleCloseCbs == NULL)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
for (i=0; _HandleCloseCbs[i] != NULL; i++)
|
||||
{
|
||||
HANDLE_CLOSE_CB *close_cb = (HANDLE_CLOSE_CB*)_HandleCloseCbs[i];
|
||||
if (close_cb && close_cb->IsHandled(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;
|
||||
}
|
||||
|
@ -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 */
|
||||
|
Loading…
Reference in New Issue
Block a user