Changes to named pipe functions based on code review.

This commit is contained in:
Mike McDonald 2014-04-18 14:02:44 -04:00
parent 5e09e37d42
commit d8c1133201
3 changed files with 30 additions and 21 deletions

View File

@ -22,7 +22,6 @@
#endif #endif
#include <winpr/handle.h> #include <winpr/handle.h>
#include <winpr/collections.h>
#ifndef _WIN32 #ifndef _WIN32
@ -37,8 +36,6 @@
#include "../handle/handle.h" #include "../handle/handle.h"
extern wArrayList* WinPR_NamedPipeBaseInstances;
BOOL CloseHandle(HANDLE hObject) BOOL CloseHandle(HANDLE hObject)
{ {
ULONG Type; ULONG Type;
@ -172,9 +169,7 @@ BOOL CloseHandle(HANDLE hObject)
if (--pipe->dwRefCount == 0) if (--pipe->dwRefCount == 0)
{ {
ArrayList_Lock(WinPR_NamedPipeBaseInstances); ArrayList_Remove(WinPR_GetBaseNamedPipeList(), pipe);
ArrayList_Remove(WinPR_NamedPipeBaseInstances, pipe);
ArrayList_Unlock(WinPR_NamedPipeBaseInstances);
if (pipe->pBaseNamedPipe) if (pipe->pBaseNamedPipe)
{ {

View File

@ -25,7 +25,6 @@
#include <winpr/path.h> #include <winpr/path.h>
#include <winpr/synch.h> #include <winpr/synch.h>
#include <winpr/handle.h> #include <winpr/handle.h>
#include <winpr/collections.h>
#include <winpr/pipe.h> #include <winpr/pipe.h>
@ -59,17 +58,22 @@
* the last instance is closed, the named pipe handle is removed from the list. * 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 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). */ /* Find the base named pipe instance (i.e., the first instance). */
pBaseNamedPipe = NULL; pBaseNamedPipe = NULL;
ArrayList_Lock(WinPR_NamedPipeBaseInstances); ArrayList_Lock(g_BaseNamedPipeList);
for (index = 0; index < ArrayList_Count(WinPR_NamedPipeBaseInstances); index++) 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) if (strcmp(p->name, lpName) == 0)
{ {
pBaseNamedPipe = p; pBaseNamedPipe = p;
break; break;
} }
} }
ArrayList_Unlock(WinPR_NamedPipeBaseInstances); ArrayList_Unlock(g_BaseNamedPipeList);
pNamedPipe = (WINPR_NAMED_PIPE*) malloc(sizeof(WINPR_NAMED_PIPE)); pNamedPipe = (WINPR_NAMED_PIPE*) malloc(sizeof(WINPR_NAMED_PIPE));
hNamedPipe = (HANDLE) pNamedPipe; hNamedPipe = (HANDLE) pNamedPipe;
@ -226,9 +230,7 @@ HANDLE CreateNamedPipeA(LPCSTR lpName, DWORD dwOpenMode, DWORD dwPipeMode, DWORD
UnixChangeFileMode(pNamedPipe->lpFilePath, 0xFFFF); UnixChangeFileMode(pNamedPipe->lpFilePath, 0xFFFF);
/* Add the named pipe to the list of base named pipe instances. */ /* Add the named pipe to the list of base named pipe instances. */
ArrayList_Lock(WinPR_NamedPipeBaseInstances); ArrayList_Add(g_BaseNamedPipeList, pNamedPipe);
ArrayList_Add(WinPR_NamedPipeBaseInstances, pNamedPipe);
ArrayList_Unlock(WinPR_NamedPipeBaseInstances);
} }
else else
{ {

View File

@ -23,6 +23,7 @@
#ifndef _WIN32 #ifndef _WIN32
#include <winpr/pipe.h> #include <winpr/pipe.h>
#include <winpr/collections.h>
#include "../handle/handle.h" #include "../handle/handle.h"
@ -34,11 +35,13 @@ struct winpr_pipe
}; };
typedef struct winpr_pipe WINPR_PIPE; typedef struct winpr_pipe WINPR_PIPE;
typedef struct winpr_named_pipe WINPR_NAMED_PIPE;
struct winpr_named_pipe struct winpr_named_pipe
{ {
WINPR_HANDLE_DEF(); WINPR_HANDLE_DEF();
struct winpr_named_pipe* pBaseNamedPipe; WINPR_NAMED_PIPE* pBaseNamedPipe;
DWORD dwRefCount; DWORD dwRefCount;
@ -59,7 +62,16 @@ struct winpr_named_pipe
DWORD dwFlagsAndAttributes; DWORD dwFlagsAndAttributes;
LPOVERLAPPED lpOverlapped; LPOVERLAPPED lpOverlapped;
}; };
typedef struct winpr_named_pipe WINPR_NAMED_PIPE;
#ifdef __cplusplus
extern "C" {
#endif
wArrayList* WinPR_GetBaseNamedPipeList();
#ifdef __cplusplus
}
#endif
#endif #endif