[or-cvs] r10827: More bugfixing with IOCPloader. (in libevent-urz/trunk: loaders sample)

Urz at seul.org Urz at seul.org
Sat Jul 14 13:52:45 UTC 2007


Author: Urz
Date: 2007-07-14 09:52:45 -0400 (Sat, 14 Jul 2007)
New Revision: 10827

Modified:
   libevent-urz/trunk/loaders/IOCPloader.c
   libevent-urz/trunk/sample/IOCPloader-test.c
Log:
More bugfixing with IOCPloader.

Modified: libevent-urz/trunk/loaders/IOCPloader.c
===================================================================
--- libevent-urz/trunk/loaders/IOCPloader.c	2007-07-14 02:32:19 UTC (rev 10826)
+++ libevent-urz/trunk/loaders/IOCPloader.c	2007-07-14 13:52:45 UTC (rev 10827)
@@ -92,7 +92,7 @@
     connList[myListElem].inUse = 1;
     
     // Despite the name, this call associates the socket with the I/O Completion port
-    IOCP = CreateIoCompletionPort(connList[myListElem].sock, IOCP, (ULONG_PTR) myListElem, 0);
+    IOCP = CreateIoCompletionPort((HANDLE) *(connList[myListElem].sock), IOCP, (ULONG_PTR) myListElem, 0);
     
     ev_unlock(connList[myListElem].lock);
     ev_unlock(listLock);
@@ -145,6 +145,7 @@
     size_t unloaded;
     DWORD WSASendFlags = 0;
     DWORD localListSize;
+    DWORD sizeRet = -1;
     
     while(1) {
         ev_lock(listLock);
@@ -172,7 +173,8 @@
                 // assume the WSABUF is full?
                 // remind us that sending is in progress and we can't overwrite the buffer
                 connList[listpos].canSend = 0;
-                printf("Sock : %d (pos %d)\n", (int) connList[listpos].sock, (int) listpos);
+                //printf("Sock : %d Overlapped %d (pos %d)\n", (int) connList[listpos].sock, (int) &(connList[listpos].sendol), (int) listpos);
+                //fflush(stdout);
                 WSASend(
                     *(connList[listpos].sock),
                     // Socket to send on
@@ -180,7 +182,7 @@
                     // 'array' of WSA buffers to use
                     1,
                     // array of size 1
-                    NULL,
+                    &sizeRet,
                     // this socket is overlapped, so can't retrieve sent size immeditately
                     WSASendFlags,
                     // any send flags
@@ -189,6 +191,9 @@
                     NULL
                     // no completion routine
                 );
+                if(sizeRet != -1) {
+                    printf("WTF?: WSASend changed sizeRet\n");
+                }
             }
             ev_unlock(connList[listpos].lock);
         }
@@ -200,7 +205,7 @@
     OLOPERATION *CompletedOverlapped;
     // See http://msdn2.microsoft.com/en-us/library/ms684342.aspx
     DWORD CompleteSize;
-    DWORD *CompletionKey;
+    DWORD CompletionKey;
     BOOL GQCSRet;
     connection *Conn;
     UINT WSARecvRet;
@@ -229,16 +234,17 @@
             continue;
         }
         
-        printf("R");
+        printf("C");
         
         // This is no error, a completed read event has occured.
         // Get the connection ths applies to.
-        Conn = &connList[*CompletionKey];
+        Conn = &connList[CompletionKey];
         
         ev_lock(Conn->lock);
         if(CompletedOverlapped->op == OP_SEND) {
             // the connection has sent all data and is ready for more
             Conn->canSend = 1;
+            printf("s");
         } else if(CompletedOverlapped->op == OP_RECV) {
             // Now we have a completed read event, perform the operations
             // required on the read data.
@@ -265,6 +271,7 @@
     			NULL
                 // The callback - we are using events for this, so that's not important
                 );
+            printf("r");
         }
         ev_unlock(Conn->lock);
     }

Modified: libevent-urz/trunk/sample/IOCPloader-test.c
===================================================================
--- libevent-urz/trunk/sample/IOCPloader-test.c	2007-07-14 02:32:19 UTC (rev 10826)
+++ libevent-urz/trunk/sample/IOCPloader-test.c	2007-07-14 13:52:45 UTC (rev 10827)
@@ -115,15 +115,18 @@
     int bindingHandle = -1;
     char buf[BUF_SIZE];
     int error;
+    BOOL AcceptRet;
     
+    DWORD zero;
+    
     WSAStartup(MAKEWORD( 2, 2 ), &wsaData);
-    IOCPLoaderInit();
     event_init();
     
     lsabe = sa_bufferevent_new(listener_on_read, NULL, NULL, NULL);
     // Obviously one or more of these has to be changed to be not-null
     
     Listen = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, WSA_FLAG_OVERLAPPED);
+    Accept = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, WSA_FLAG_OVERLAPPED);
     
     if(Listen == INVALID_SOCKET) {
         printf("Oh noes! WSASocket failed\n");
@@ -146,14 +149,15 @@
     
     printf("Listening...\n");
 
-    Accept = accept(Listen, NULL, NULL);
-    if (Accept == INVALID_SOCKET) {
-        printf("Oh noes! Accept failed\n");
-        exit(0);
-    }
+
+    Accept = WSAAccept(Listen, NULL, NULL, NULL, 0);
+    // accept() and overlapped IO do not play well together.
+    
+    printf("Client Accepted...\n");
+    
+    IOCPLoaderInit();
+    // If we start this up before all the accepting is done it may interfere.
 
-    printf("Client Accepted...\n");
-
     bindingHandle = IOCPloader_bind(&Accept, lsabe);
     printf("IOCPLoader Bound (%d)\n", bindingHandle);
     



More information about the tor-commits mailing list