From d8c11332014bcc497e41267fd5be857257c76d3a Mon Sep 17 00:00:00 2001 From: Mike McDonald Date: Fri, 18 Apr 2014 14:02:44 -0400 Subject: [PATCH] Changes to named pipe functions based on code review. --- winpr/libwinpr/handle/handle.c | 7 +------ winpr/libwinpr/pipe/pipe.c | 28 +++++++++++++++------------- winpr/libwinpr/pipe/pipe.h | 16 ++++++++++++++-- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/winpr/libwinpr/handle/handle.c b/winpr/libwinpr/handle/handle.c index 150019087..ed4dbaa35 100644 --- a/winpr/libwinpr/handle/handle.c +++ b/winpr/libwinpr/handle/handle.c @@ -22,7 +22,6 @@ #endif #include -#include #ifndef _WIN32 @@ -37,8 +36,6 @@ #include "../handle/handle.h" -extern wArrayList* WinPR_NamedPipeBaseInstances; - BOOL CloseHandle(HANDLE hObject) { ULONG Type; @@ -172,9 +169,7 @@ BOOL CloseHandle(HANDLE hObject) if (--pipe->dwRefCount == 0) { - ArrayList_Lock(WinPR_NamedPipeBaseInstances); - ArrayList_Remove(WinPR_NamedPipeBaseInstances, pipe); - ArrayList_Unlock(WinPR_NamedPipeBaseInstances); + ArrayList_Remove(WinPR_GetBaseNamedPipeList(), pipe); if (pipe->pBaseNamedPipe) { diff --git a/winpr/libwinpr/pipe/pipe.c b/winpr/libwinpr/pipe/pipe.c index 3384caaee..3694de249 100644 --- a/winpr/libwinpr/pipe/pipe.c +++ b/winpr/libwinpr/pipe/pipe.c @@ -25,7 +25,6 @@ #include #include #include -#include #include @@ -59,17 +58,22 @@ * the last instance is closed, the named pipe handle is removed from the list. */ -wArrayList* WinPR_NamedPipeBaseInstances; +static wArrayList* g_BaseNamedPipeList; + +static BOOL g_Initialized = FALSE; static void InitWinPRPipeModule() { - static BOOL bInitialized = FALSE; + if (g_Initialized) return; - if (bInitialized) return; + g_BaseNamedPipeList = ArrayList_New(TRUE); - WinPR_NamedPipeBaseInstances = ArrayList_New(TRUE); + g_Initialized = TRUE; +} - bInitialized = TRUE; +wArrayList* WinPR_GetBaseNamedPipeList() +{ + return g_BaseNamedPipeList; } @@ -141,17 +145,17 @@ HANDLE CreateNamedPipeA(LPCSTR lpName, DWORD dwOpenMode, DWORD dwPipeMode, DWORD /* Find the base named pipe instance (i.e., the first instance). */ pBaseNamedPipe = NULL; - ArrayList_Lock(WinPR_NamedPipeBaseInstances); - for (index = 0; index < ArrayList_Count(WinPR_NamedPipeBaseInstances); index++) + ArrayList_Lock(g_BaseNamedPipeList); + for (index = 0; index < ArrayList_Count(g_BaseNamedPipeList); index++) { - WINPR_NAMED_PIPE* p = (WINPR_NAMED_PIPE*) ArrayList_GetItem(WinPR_NamedPipeBaseInstances, index); + WINPR_NAMED_PIPE* p = (WINPR_NAMED_PIPE*) ArrayList_GetItem(g_BaseNamedPipeList, index); if (strcmp(p->name, lpName) == 0) { pBaseNamedPipe = p; break; } } - ArrayList_Unlock(WinPR_NamedPipeBaseInstances); + ArrayList_Unlock(g_BaseNamedPipeList); pNamedPipe = (WINPR_NAMED_PIPE*) malloc(sizeof(WINPR_NAMED_PIPE)); hNamedPipe = (HANDLE) pNamedPipe; @@ -226,9 +230,7 @@ HANDLE CreateNamedPipeA(LPCSTR lpName, DWORD dwOpenMode, DWORD dwPipeMode, DWORD UnixChangeFileMode(pNamedPipe->lpFilePath, 0xFFFF); /* Add the named pipe to the list of base named pipe instances. */ - ArrayList_Lock(WinPR_NamedPipeBaseInstances); - ArrayList_Add(WinPR_NamedPipeBaseInstances, pNamedPipe); - ArrayList_Unlock(WinPR_NamedPipeBaseInstances); + ArrayList_Add(g_BaseNamedPipeList, pNamedPipe); } else { diff --git a/winpr/libwinpr/pipe/pipe.h b/winpr/libwinpr/pipe/pipe.h index 042918b94..1c83fed20 100644 --- a/winpr/libwinpr/pipe/pipe.h +++ b/winpr/libwinpr/pipe/pipe.h @@ -23,6 +23,7 @@ #ifndef _WIN32 #include +#include #include "../handle/handle.h" @@ -34,11 +35,13 @@ struct winpr_pipe }; typedef struct winpr_pipe WINPR_PIPE; +typedef struct winpr_named_pipe WINPR_NAMED_PIPE; + struct winpr_named_pipe { WINPR_HANDLE_DEF(); - struct winpr_named_pipe* pBaseNamedPipe; + WINPR_NAMED_PIPE* pBaseNamedPipe; DWORD dwRefCount; @@ -59,7 +62,16 @@ struct winpr_named_pipe DWORD dwFlagsAndAttributes; LPOVERLAPPED lpOverlapped; }; -typedef struct winpr_named_pipe WINPR_NAMED_PIPE; + +#ifdef __cplusplus +extern "C" { +#endif + +wArrayList* WinPR_GetBaseNamedPipeList(); + +#ifdef __cplusplus +} +#endif #endif