Mike McCormack : rpcrt4: Isolate code to open named pipes out of RPCRT4_OpenConnection.

Alexandre Julliard julliard at wine.codeweavers.com
Wed Apr 19 13:15:00 CDT 2006


Module: wine
Branch: refs/heads/master
Commit: 7e709cf25811427c11d024bbfcf6e48772526319
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=7e709cf25811427c11d024bbfcf6e48772526319

Author: Mike McCormack <mike at codeweavers.com>
Date:   Wed Apr 19 18:14:30 2006 +0900

rpcrt4: Isolate code to open named pipes out of RPCRT4_OpenConnection.

---

 dlls/rpcrt4/rpc_binding.c |   76 +++++++++++++++++++++++----------------------
 1 files changed, 39 insertions(+), 37 deletions(-)

diff --git a/dlls/rpcrt4/rpc_binding.c b/dlls/rpcrt4/rpc_binding.c
index a3b5fec..d5b1aef 100644
--- a/dlls/rpcrt4/rpc_binding.c
+++ b/dlls/rpcrt4/rpc_binding.c
@@ -129,11 +129,42 @@ RPC_STATUS RPCRT4_DestroyConnection(RpcC
   return RPC_S_OK;
 }
 
+static RPC_STATUS rpcrt4_connect_pipe(RpcConnection *Connection, LPCSTR pname)
+{
+  TRACE("listening on %s\n", pname);
+
+  Connection->conn = CreateNamedPipeA(pname, PIPE_ACCESS_DUPLEX,
+                                      PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE,
+                                      PIPE_UNLIMITED_INSTANCES,
+                                      RPC_MAX_PACKET_SIZE, RPC_MAX_PACKET_SIZE, 5000, NULL);
+  memset(&Connection->ovl, 0, sizeof(Connection->ovl));
+  Connection->ovl.hEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
+  if (ConnectNamedPipe(Connection->conn, &Connection->ovl))
+     return RPC_S_OK;
+
+  WARN("Couldn't ConnectNamedPipe (error was %ld)\n", GetLastError());
+  if (GetLastError() == ERROR_PIPE_CONNECTED) {
+    SetEvent(Connection->ovl.hEvent);
+    return RPC_S_OK;
+  }
+  if (GetLastError() == ERROR_IO_PENDING) {
+    /* FIXME: looks like we need to GetOverlappedResult here? */
+    return RPC_S_OK;
+  }
+  return RPC_S_SERVER_UNAVAILABLE;
+}
+
 RPC_STATUS RPCRT4_OpenConnection(RpcConnection* Connection)
 {
+  RPC_STATUS r = RPC_S_OK;
+
   TRACE("(Connection == ^%p)\n", Connection);
-  if (!Connection->conn) {
-    if (Connection->server) { /* server */
+
+  /* already connected? */
+  if (Connection->conn)
+     return r;
+
+  if (Connection->server) { /* server */
       /* protseq=ncalrpc: supposed to use NT LPC ports,
        * but we'll implement it with named pipes for now */
       if (strcmp(Connection->Protseq, "ncalrpc") == 0) {
@@ -142,22 +173,8 @@ RPC_STATUS RPCRT4_OpenConnection(RpcConn
         pname = HeapAlloc(GetProcessHeap(), 0, strlen(prefix) + strlen(Connection->Endpoint) + 1);
         strcat(strcpy(pname, prefix), Connection->Endpoint);
         TRACE("listening on %s\n", pname);
-        Connection->conn = CreateNamedPipeA(pname, PIPE_ACCESS_DUPLEX,
-                                         PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE, PIPE_UNLIMITED_INSTANCES,
-                                         RPC_MAX_PACKET_SIZE, RPC_MAX_PACKET_SIZE, 5000, NULL);
+        r = rpcrt4_connect_pipe(Connection, pname);
         HeapFree(GetProcessHeap(), 0, pname);
-        memset(&Connection->ovl, 0, sizeof(Connection->ovl));
-        Connection->ovl.hEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
-        if (!ConnectNamedPipe(Connection->conn, &Connection->ovl)) {
-          WARN("Couldn't ConnectNamedPipe (error was %ld)\n", GetLastError());
-          if (GetLastError() == ERROR_PIPE_CONNECTED) {
-            SetEvent(Connection->ovl.hEvent);
-            return RPC_S_OK;
-          } else if (GetLastError() == ERROR_IO_PENDING) {
-            return RPC_S_OK;
-          }
-          return RPC_S_SERVER_UNAVAILABLE;
-        }
       }
       /* protseq=ncacn_np: named pipes */
       else if (strcmp(Connection->Protseq, "ncacn_np") == 0) {
@@ -165,30 +182,15 @@ RPC_STATUS RPCRT4_OpenConnection(RpcConn
         LPSTR pname;
         pname = HeapAlloc(GetProcessHeap(), 0, strlen(prefix) + strlen(Connection->Endpoint) + 1);
         strcat(strcpy(pname, prefix), Connection->Endpoint);
-        TRACE("listening on %s\n", pname);
-        Connection->conn = CreateNamedPipeA(pname, PIPE_ACCESS_DUPLEX,
-                                         PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES,
-                                         RPC_MAX_PACKET_SIZE, RPC_MAX_PACKET_SIZE, 5000, NULL);
+        r = rpcrt4_connect_pipe(Connection, pname);
         HeapFree(GetProcessHeap(), 0, pname);
-        memset(&Connection->ovl, 0, sizeof(Connection->ovl));
-        Connection->ovl.hEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
-        if (!ConnectNamedPipe(Connection->conn, &Connection->ovl)) {
-          if (GetLastError() == ERROR_PIPE_CONNECTED) {
-            SetEvent(Connection->ovl.hEvent);
-            return RPC_S_OK;
-          } else if (GetLastError() == ERROR_IO_PENDING) {
-            return RPC_S_OK;
-          }
-          WARN("Couldn't ConnectNamedPipe (error was %ld)\n", GetLastError());
-          return RPC_S_SERVER_UNAVAILABLE;
-        }
       }
       else {
         ERR("protseq %s not supported\n", Connection->Protseq);
         return RPC_S_PROTSEQ_NOT_SUPPORTED;
       }
-    }
-    else { /* client */
+  }
+  else { /* client */
       /* protseq=ncalrpc: supposed to use NT LPC ports,
        * but we'll implement it with named pipes for now */
       if (strcmp(Connection->Protseq, "ncalrpc") == 0) {
@@ -265,9 +267,9 @@ RPC_STATUS RPCRT4_OpenConnection(RpcConn
         ERR("protseq %s not supported\n", Connection->Protseq);
         return RPC_S_PROTSEQ_NOT_SUPPORTED;
       }
-    }
   }
-  return RPC_S_OK;
+
+  return r;
 }
 
 RPC_STATUS RPCRT4_CloseConnection(RpcConnection* Connection)




More information about the wine-cvs mailing list