[ros-dev] Re: [ros-svn] [hbirr] 14296: - Guarded the calls to IoSetCancelRoutine with IoAcquireCancelSpinLock/IoReleaseCancelSpinLock.

Hartmut Birr hartmut.birr at gmx.de
Sat Mar 26 18:32:21 CET 2005


Hartmut Birr wrote:

>Possible that is not correct. I see debug messages from read and write
>request at the same time. I see also that the written length from write
>request is shown as result for a read request. I've add a local
>overlapped structure in RPCRT4_Send. This does fix this problem. 
>
Forgot to add the diff.

- Hartmut

-------------- next part --------------
Index: lib/rpcrt4/rpc_message.c
===================================================================
--- lib/rpcrt4/rpc_message.c	(revision 14297)
+++ lib/rpcrt4/rpc_message.c	(working copy)
@@ -44,6 +44,12 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(ole);
 
+#undef WARN
+#define WARN DPRINT1
+
+#undef TRACE
+#define TRACE DPRINT1
+
 DWORD RPCRT4_GetHeaderSize(RpcPktHdr *Header)
 {
   static const DWORD header_sizes[] = {
@@ -247,7 +253,14 @@
 {
   PUCHAR buffer_pos;
   DWORD hdr_size, count;
+  OVERLAPPED ovl;
+  RPC_STATUS status;
 
+  memset(&ovl, 0, sizeof(OVERLAPPED));
+  ovl.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
+  
+  TRACE("%x %x %x %d\n", Connection, Header, Buffer, BufferLength);
+
   buffer_pos = Buffer;
   /* The packet building functions save the packet header size, so we can use it. */
   hdr_size = Header->common.frag_len;
@@ -265,35 +278,45 @@
     }
 
     /* transmit packet header */
-    if (!WriteFile(Connection->conn, Header, hdr_size, &count, &Connection->ovl)) {
+    if (!WriteFile(Connection->conn, Header, hdr_size, &count, &/*Connection->*/ovl) &&
+	ERROR_IO_PENDING != GetLastError()) {
       WARN("WriteFile failed with error %ld\n", GetLastError());
-      return GetLastError();
+      status = GetLastError();
+      goto done;
     }
-    if (!GetOverlappedResult(Connection->conn, &Connection->ovl, &count, TRUE)) {
+    if (!GetOverlappedResult(Connection->conn, &/*Connection->*/ovl, &count, TRUE)) {
       WARN("GetOverlappedResult failed with error %ld\n", GetLastError());
-      return GetLastError();
+      status = GetLastError();
+      goto done;
     }
 
     /* fragment consisted of header only and is the last one */
     if (hdr_size == Header->common.frag_len &&
         Header->common.flags & RPC_FLG_LAST) {
-      return RPC_S_OK;
+      status =RPC_S_OK;
+      goto done;
     }
 
     /* send the fragment data */
-    if (!WriteFile(Connection->conn, buffer_pos, Header->common.frag_len - hdr_size, &count, &Connection->ovl)) {
+    if (!WriteFile(Connection->conn, buffer_pos, Header->common.frag_len - hdr_size, &count, &/*Connection->*/ovl) &&
+	ERROR_IO_PENDING != GetLastError()) {
       WARN("WriteFile failed with error %ld\n", GetLastError());
-      return GetLastError();
+      status = GetLastError();
+      goto done;
     }
-    if (!GetOverlappedResult(Connection->conn, &Connection->ovl, &count, TRUE)) {
+    if (!GetOverlappedResult(Connection->conn, &/*Connection->*/ovl, &count, TRUE)) {
       WARN("GetOverlappedResult failed with error %ld\n", GetLastError());
-      return GetLastError();
+      status = GetLastError();
+      goto done;
     }
 
     Header->common.flags &= ~RPC_FLG_FIRST;
   }
 
-  return RPC_S_OK;
+  status = RPC_S_OK;
+done:
+  CloseHandle(ovl.hEvent);
+  return status;
 }
 
 /***********************************************************************
@@ -317,7 +340,8 @@
   TRACE("(%p, %p, %p)\n", Connection, Header, pMsg);
 
   /* read packet common header */
-  if (!ReadFile(Connection->conn, &common_hdr, sizeof(common_hdr), &dwRead, &Connection->ovl)) {
+  if (!ReadFile(Connection->conn, &common_hdr, sizeof(common_hdr), &dwRead, &Connection->ovl) &&
+      ERROR_IO_PENDING != GetLastError()) {
     WARN("ReadFile failed with error %ld\n", GetLastError());
     status = RPC_S_PROTOCOL_ERROR;
     goto fail;
@@ -355,7 +379,8 @@
 
   /* read the rest of packet header */
   if (!ReadFile(Connection->conn, &(*Header)->common + 1,
-                hdr_length - sizeof(common_hdr), &dwRead, &Connection->ovl)) {
+                hdr_length - sizeof(common_hdr), &dwRead, &Connection->ovl) &&
+      ERROR_IO_PENDING != GetLastError()) {
     WARN("ReadFile failed with error %ld\n", GetLastError());
     status = RPC_S_PROTOCOL_ERROR;
     goto fail;
@@ -405,7 +430,8 @@
     }
 
     if (data_length == 0) dwRead = 0; else {
-      if (!ReadFile(Connection->conn, buffer_ptr, data_length, &dwRead, &Connection->ovl)) {
+      if (!ReadFile(Connection->conn, buffer_ptr, data_length, &dwRead, &Connection->ovl) &&
+	  ERROR_IO_PENDING != GetLastError()) {
         WARN("ReadFile failed with error %ld\n", GetLastError());
         status = RPC_S_PROTOCOL_ERROR;
         goto fail;
@@ -437,7 +463,8 @@
       TRACE("next header\n");
 
       /* read the header of next packet */
-      if (!ReadFile(Connection->conn, *Header, hdr_length, &dwRead, &Connection->ovl)) {
+      if (!ReadFile(Connection->conn, *Header, hdr_length, &dwRead, &Connection->ovl) &&
+	  ERROR_IO_PENDING != GetLastError()) {
         WARN("ReadFile failed with error %ld\n", GetLastError());
         status = GetLastError();
         goto fail;


More information about the Ros-dev mailing list