libwinpr-pipe: fix circular dependency
authorMarc-André Moreau <marcandre.moreau@gmail.com>
Thu, 8 May 2014 21:17:39 +0000 (17:17 -0400)
committerMarc-André Moreau <marcandre.moreau@gmail.com>
Thu, 8 May 2014 21:17:39 +0000 (17:17 -0400)
winpr/libwinpr/handle/handle.c
winpr/libwinpr/pipe/pipe.c
winpr/libwinpr/pipe/pipe.h

index ed4dbaa..c7c7bfe 100644 (file)
@@ -169,7 +169,7 @@ BOOL CloseHandle(HANDLE hObject)
 
                if (--pipe->dwRefCount == 0)
                {
-                       ArrayList_Remove(WinPR_GetBaseNamedPipeList(), pipe);
+                       pipe->pfnRemoveBaseNamedPipeFromList(pipe);
 
                        if (pipe->pBaseNamedPipe)
                        {
index 0ee2a6c..a207b9c 100644 (file)
@@ -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;
index 1c83fed..99ed438 100644 (file)
@@ -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,17 +63,9 @@ struct winpr_named_pipe
        DWORD nDefaultTimeOut;
        DWORD dwFlagsAndAttributes;
        LPOVERLAPPED lpOverlapped;
-};
-
-#ifdef __cplusplus
-extern "C" {
-#endif
 
-wArrayList* WinPR_GetBaseNamedPipeList();
-
-#ifdef __cplusplus
-}
-#endif
+       fnRemoveBaseNamedPipeFromList pfnRemoveBaseNamedPipeFromList;
+};
 
 #endif