diff --git a/winpr/libwinpr/handle/handle.c b/winpr/libwinpr/handle/handle.c index ed4dbaa35..c7c7bfeda 100644 --- a/winpr/libwinpr/handle/handle.c +++ b/winpr/libwinpr/handle/handle.c @@ -169,7 +169,7 @@ BOOL CloseHandle(HANDLE hObject) if (--pipe->dwRefCount == 0) { - ArrayList_Remove(WinPR_GetBaseNamedPipeList(), pipe); + pipe->pfnRemoveBaseNamedPipeFromList(pipe); if (pipe->pBaseNamedPipe) { diff --git a/winpr/libwinpr/pipe/pipe.c b/winpr/libwinpr/pipe/pipe.c index 0ee2a6c63..a207b9c7a 100644 --- a/winpr/libwinpr/pipe/pipe.c +++ b/winpr/libwinpr/pipe/pipe.c @@ -45,7 +45,7 @@ #include "pipe.h" /* - * Since the WINPR implementation of named pipes makes use of UNIX domain + * Since the WinPR implementation of named pipes makes use of UNIX domain * sockets, it is not possible to bind the same name more than once (i.e., * SO_REUSEADDR does not work with UNIX domain sockets). As a result, the * first call to CreateNamedPipe must create the UNIX domain socket and @@ -64,19 +64,19 @@ static BOOL g_Initialized = FALSE; static void InitWinPRPipeModule() { - if (g_Initialized) return; + if (g_Initialized) + return; g_BaseNamedPipeList = ArrayList_New(TRUE); g_Initialized = TRUE; } -wArrayList* WinPR_GetBaseNamedPipeList() +void WinPR_RemoveBaseNamedPipeFromList(WINPR_NAMED_PIPE* pNamedPipe) { - return g_BaseNamedPipeList; + ArrayList_Remove(g_BaseNamedPipeList, pNamedPipe); } - /* * Unnamed pipe */ @@ -146,15 +146,18 @@ HANDLE CreateNamedPipeA(LPCSTR lpName, DWORD dwOpenMode, DWORD dwPipeMode, DWORD pBaseNamedPipe = NULL; ArrayList_Lock(g_BaseNamedPipeList); + for (index = 0; index < ArrayList_Count(g_BaseNamedPipeList); index++) { WINPR_NAMED_PIPE* p = (WINPR_NAMED_PIPE*) ArrayList_GetItem(g_BaseNamedPipeList, index); + if (strcmp(p->name, lpName) == 0) { pBaseNamedPipe = p; break; } } + ArrayList_Unlock(g_BaseNamedPipeList); pNamedPipe = (WINPR_NAMED_PIPE*) malloc(sizeof(WINPR_NAMED_PIPE)); @@ -162,6 +165,8 @@ HANDLE CreateNamedPipeA(LPCSTR lpName, DWORD dwOpenMode, DWORD dwPipeMode, DWORD WINPR_HANDLE_SET_TYPE(pNamedPipe, HANDLE_TYPE_NAMED_PIPE); + pNamedPipe->pfnRemoveBaseNamedPipeFromList = WinPR_RemoveBaseNamedPipeFromList; + pNamedPipe->name = _strdup(lpName); pNamedPipe->dwOpenMode = dwOpenMode; pNamedPipe->dwPipeMode = dwPipeMode; diff --git a/winpr/libwinpr/pipe/pipe.h b/winpr/libwinpr/pipe/pipe.h index 1c83fed20..99ed43870 100644 --- a/winpr/libwinpr/pipe/pipe.h +++ b/winpr/libwinpr/pipe/pipe.h @@ -37,6 +37,8 @@ typedef struct winpr_pipe WINPR_PIPE; typedef struct winpr_named_pipe WINPR_NAMED_PIPE; +typedef void ( * fnRemoveBaseNamedPipeFromList)(WINPR_NAMED_PIPE* pNamedPipe); + struct winpr_named_pipe { WINPR_HANDLE_DEF(); @@ -61,18 +63,10 @@ struct winpr_named_pipe DWORD nDefaultTimeOut; DWORD dwFlagsAndAttributes; LPOVERLAPPED lpOverlapped; + + fnRemoveBaseNamedPipeFromList pfnRemoveBaseNamedPipeFromList; }; -#ifdef __cplusplus -extern "C" { -#endif - -wArrayList* WinPR_GetBaseNamedPipeList(); - -#ifdef __cplusplus -} -#endif - #endif #endif /* WINPR_PIPE_PRIVATE_H */