Remove the RPC connection cache

Mike Hearn mike at navi.cx
Thu Jun 17 10:00:22 CDT 2004


Thanks to Rob Shearman and Andrew Bartlet for helping me debug this one.

Mike Hearn <mike at navi.cx>
Remove the RPC connection cache as Windows does not allow multiple binds
on the same connection.

Index: dlls/rpcrt4/rpc_binding.c
===================================================================
RCS file: /home/wine/wine/dlls/rpcrt4/rpc_binding.c,v
retrieving revision 1.26
diff -u -p -r1.26 rpc_binding.c
--- dlls/rpcrt4/rpc_binding.c	16 Jun 2004 20:07:19 -0000	1.26
+++ dlls/rpcrt4/rpc_binding.c	17 Jun 2004 14:58:54 -0000
@@ -46,17 +46,6 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(ole);
 
-static RpcConnection* conn_cache;
-
-static CRITICAL_SECTION conn_cache_cs;
-static CRITICAL_SECTION_DEBUG critsect_debug =
-{
-    0, 0, &conn_cache_cs,
-    { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
-      0, 0, { 0, (DWORD)(__FILE__ ": conn_cache_cs") }
-};
-static CRITICAL_SECTION conn_cache_cs = { &critsect_debug, -1, 0, 0, 0, 0 };
-
 LPSTR RPCRT4_strndupA(LPCSTR src, INT slen)
 {
   DWORD len;
@@ -122,11 +111,6 @@ RPC_STATUS RPCRT4_CreateConnection(RpcCo
   NewConnection->Used = Binding;
   NewConnection->MaxTransmissionSize = RPC_MAX_PACKET_SIZE;
 
-  EnterCriticalSection(&conn_cache_cs);
-  NewConnection->Next = conn_cache;
-  conn_cache = NewConnection;
-  LeaveCriticalSection(&conn_cache_cs);
-
   TRACE("connection: %p\n", NewConnection);
   *Connection = NewConnection;
 
@@ -135,22 +119,9 @@ RPC_STATUS RPCRT4_CreateConnection(RpcCo
 
 RPC_STATUS RPCRT4_DestroyConnection(RpcConnection* Connection)
 {
-  RpcConnection* PrevConnection;
-
   TRACE("connection: %p\n", Connection);
   if (Connection->Used) ERR("connection is still in use\n");
 
-  EnterCriticalSection(&conn_cache_cs);
-  PrevConnection = conn_cache;
-  if (PrevConnection == Connection) {
-    conn_cache = Connection->Next;
-  } else {
-    while (PrevConnection && PrevConnection->Next != Connection)
-      PrevConnection = PrevConnection->Next;
-    if (PrevConnection) PrevConnection->Next = Connection->Next;
-  }
-  LeaveCriticalSection(&conn_cache_cs);
-
   RPCRT4_CloseConnection(Connection);
   RPCRT4_strfree(Connection->Endpoint);
   RPCRT4_strfree(Connection->NetworkAddr);
@@ -159,44 +130,6 @@ RPC_STATUS RPCRT4_DestroyConnection(RpcC
   return RPC_S_OK;
 }
 
-RPC_STATUS RPCRT4_GetConnection(RpcConnection** Connection, BOOL server, LPSTR Protseq, LPSTR NetworkAddr, LPSTR Endpoint, LPSTR NetworkOptions, RpcBinding* Binding)
-{
-  RpcConnection* NewConnection;
-
-  if (!server) {
-    EnterCriticalSection(&conn_cache_cs);
-    for (NewConnection = conn_cache; NewConnection; NewConnection = NewConnection->Next) {
-      if (NewConnection->Used) continue;
-      if (NewConnection->server != server) continue;
-      if (Protseq && strcmp(NewConnection->Protseq, Protseq)) continue;
-      if (NetworkAddr && strcmp(NewConnection->NetworkAddr, NetworkAddr)) continue;
-      if (Endpoint && strcmp(NewConnection->Endpoint, Endpoint)) continue;
-      /* this connection fits the bill */
-      NewConnection->Used = Binding;
-      break;
-    }
-    LeaveCriticalSection(&conn_cache_cs);
-    if (NewConnection) {
-      TRACE("cached connection: %p\n", NewConnection);
-      *Connection = NewConnection;
-      return RPC_S_OK;
-    }
-  }
-  return RPCRT4_CreateConnection(Connection, server, Protseq, NetworkAddr, Endpoint, NetworkOptions, Binding);
-}
-
-RPC_STATUS RPCRT4_ReleaseConnection(RpcConnection* Connection)
-{
-  TRACE("connection: %p\n", Connection);
-  Connection->Used = NULL;
-  if (!Connection->server) {
-    /* cache the open connection for reuse later */
-    /* FIXME: we should probably clean the cache someday */
-    return RPC_S_OK;
-  }
-  return RPCRT4_DestroyConnection(Connection);
-}
-
 RPC_STATUS RPCRT4_OpenConnection(RpcConnection* Connection)
 {
   TRACE("(Connection == ^%p)\n", Connection);
@@ -516,7 +449,7 @@ RPC_STATUS RPCRT4_OpenBinding(RpcBinding
              sizeof(RPC_SYNTAX_IDENTIFIER))) {
 
     TRACE("releasing pre-existing connection\n");
-    RPCRT4_ReleaseConnection(Binding->FromConn);
+    RPCRT4_DestroyConnection(Binding->FromConn);
     Binding->FromConn = NULL;
   } else {
     /* we already have an connection with acceptable binding, so use it */
@@ -527,7 +460,7 @@ RPC_STATUS RPCRT4_OpenBinding(RpcBinding
   }
   
   /* create a new connection */
-  RPCRT4_GetConnection(&NewConnection, Binding->server, Binding->Protseq, Binding->NetworkAddr, Binding->Endpoint, NULL, Binding);
+  RPCRT4_CreateConnection(&NewConnection, Binding->server, Binding->Protseq, Binding->NetworkAddr, Binding->Endpoint, NULL, Binding);
   *Connection = NewConnection;
   status = RPCRT4_OpenConnection(NewConnection);
   if (status != RPC_S_OK) {
@@ -549,27 +482,27 @@ RPC_STATUS RPCRT4_OpenBinding(RpcBinding
 
     status = RPCRT4_Send(*Connection, hdr, NULL, 0);
     if (status != RPC_S_OK) {
-      RPCRT4_ReleaseConnection(*Connection);
+      RPCRT4_DestroyConnection(*Connection);
       return status;
     }
 
     response = HeapAlloc(GetProcessHeap(), 0, RPC_MAX_PACKET_SIZE);
     if (response == NULL) {
       WARN("Can't allocate memory for binding response\n");
-      RPCRT4_ReleaseConnection(*Connection);
+      RPCRT4_DestroyConnection(*Connection);
       return E_OUTOFMEMORY;
     }
 
     /* get a reply */
     if (!ReadFile(NewConnection->conn, response, RPC_MAX_PACKET_SIZE, &count, NULL)) {
       WARN("ReadFile failed with error %ld\n", GetLastError());
-      RPCRT4_ReleaseConnection(*Connection);
+      RPCRT4_DestroyConnection(*Connection);
       return RPC_S_PROTOCOL_ERROR;
     }
 
     if (count < sizeof(response_hdr->common)) {
       WARN("received invalid header\n");
-      RPCRT4_ReleaseConnection(*Connection);
+      RPCRT4_DestroyConnection(*Connection);
       return RPC_S_PROTOCOL_ERROR;
     }
 
@@ -579,13 +512,13 @@ RPC_STATUS RPCRT4_OpenBinding(RpcBinding
         response_hdr->common.rpc_ver_minor != RPC_VER_MINOR ||
         response_hdr->common.ptype != PKT_BIND_ACK) {
       WARN("invalid protocol version or rejection packet\n");
-      RPCRT4_ReleaseConnection(*Connection);
+      RPCRT4_DestroyConnection(*Connection);
       return RPC_S_PROTOCOL_ERROR;
     }
 
     if (response_hdr->bind_ack.max_tsize < RPC_MIN_PACKET_SIZE) {
       WARN("server doesn't allow large enough packets\n");
-      RPCRT4_ReleaseConnection(*Connection);
+      RPCRT4_DestroyConnection(*Connection);
       return RPC_S_PROTOCOL_ERROR;
     }
 
@@ -603,7 +536,7 @@ RPC_STATUS RPCRT4_CloseBinding(RpcBindin
   TRACE("(Binding == ^%p)\n", Binding);
   if (!Connection) return RPC_S_OK;
   if (Binding->FromConn == Connection) return RPC_S_OK;
-  return RPCRT4_ReleaseConnection(Connection);
+  return RPCRT4_DestroyConnection(Connection);
 }
 
 /* utility functions for string composing and parsing */
Index: dlls/rpcrt4/rpc_server.c
===================================================================
RCS file: /home/wine/wine/dlls/rpcrt4/rpc_server.c,v
retrieving revision 1.29
diff -u -p -r1.29 rpc_server.c
--- dlls/rpcrt4/rpc_server.c	26 Apr 2004 23:33:39 -0000	1.29
+++ dlls/rpcrt4/rpc_server.c	17 Jun 2004 14:58:54 -0000
@@ -153,6 +153,7 @@ static RpcServerInterface* RPCRT4_find_i
     cif = cif->Next;
   }
   LeaveCriticalSection(&server_cs);
+  TRACE("returning %p for %s\n", cif, debugstr_guid(object));
   return cif;
 }
 
@@ -226,17 +227,18 @@ static void RPCRT4_process_packet(RpcCon
       /* FIXME: do more checks! */
       if (hdr->bind.max_tsize < RPC_MIN_PACKET_SIZE ||
           !UuidIsNil(&conn->ActiveInterface.SyntaxGUID, &status)) {
+        TRACE("packet size less than min size, or active interface syntax guid non-null\n");
         sif = NULL;
       } else {
         sif = RPCRT4_find_interface(NULL, &hdr->bind.abstract, FALSE);
       }
       if (sif == NULL) {
-        TRACE("rejecting bind request\n");
+        TRACE("rejecting bind request on connection %p\n", conn);
         /* Report failure to client. */
         response = RPCRT4_BuildBindNackHeader(NDR_LOCAL_DATA_REPRESENTATION,
                                               RPC_VER_MAJOR, RPC_VER_MINOR);
       } else {
-        TRACE("accepting bind request\n");
+        TRACE("accepting bind request on connection %p\n", conn);
 
         /* accept. */
         response = RPCRT4_BuildBindAckHeader(NDR_LOCAL_DATA_REPRESENTATION,



More information about the wine-patches mailing list