[or-cvs] r10617: Minor debugging work - read/write don't work on socketpairs (in libevent-urz/trunk: . WIN32-Code)

Urz at seul.org Urz at seul.org
Sat Jun 16 11:58:23 UTC 2007


Author: Urz
Date: 2007-06-16 07:58:23 -0400 (Sat, 16 Jun 2007)
New Revision: 10617

Modified:
   libevent-urz/trunk/WIN32-Code/win32.c
   libevent-urz/trunk/sa_evbuffer.c
Log:
Minor debugging work - read/write don't work on socketpairs on windows, so macros now make this platform agnostic. The first delayed callback works, subsequent do not. I may not be using EV_PERSIST correctly.

Modified: libevent-urz/trunk/WIN32-Code/win32.c
===================================================================
--- libevent-urz/trunk/WIN32-Code/win32.c	2007-06-16 10:31:14 UTC (rev 10616)
+++ libevent-urz/trunk/WIN32-Code/win32.c	2007-06-16 11:58:23 UTC (rev 10617)
@@ -299,7 +299,7 @@
 	memcpy(out->fd_array, in->fd_array, in->fd_count * (sizeof(SOCKET)));
 }
 
-/*
+
   static void dump_fd_set(struct win_fd_set *s)
   {
   unsigned int i;
@@ -308,8 +308,8 @@
   printf("%d ",(int)s->fd_array[i]);
   printf("]\n");
   }
-*/
 
+
 int
 win32_dispatch(struct event_base *base, void *op,
 	       struct timeval *tv)
@@ -329,17 +329,26 @@
 
 	if (!fd_count) {
 		/* Windows doesn't like you to call select() with no sockets */
+        event_debug(("%s: fd_count == 0", __func__));
 		Sleep(timeval_to_ms(tv));
 		signal_process();
 		return (0);
 	}
 
+    dump_fd_set(win32op->readset_out);
+    dump_fd_set(win32op->writeset_out);
+    dump_fd_set(win32op->exset_out);
+    event_debug(("%s: tv == %x\n", __func__, res));
+    
 	res = select(fd_count,
 		     (struct fd_set*)win32op->readset_out,
 		     (struct fd_set*)win32op->writeset_out,
 		     (struct fd_set*)win32op->exset_out, tv);
 
 	event_debug(("%s: select returned %d", __func__, res));
+    if(res == SOCKET_ERROR) {
+        event_debug(("Socket error found\n"));
+    }
 
 	if(res <= 0) {
 		signal_process();

Modified: libevent-urz/trunk/sa_evbuffer.c
===================================================================
--- libevent-urz/trunk/sa_evbuffer.c	2007-06-16 10:31:14 UTC (rev 10616)
+++ libevent-urz/trunk/sa_evbuffer.c	2007-06-16 11:58:23 UTC (rev 10617)
@@ -56,7 +56,12 @@
 #include <windows.h>
 #include <process.h>
 #include "WIN32-Code/misc.h"
+#define pipe_write(pipe, data, len) send((pipe), (data), (len), 0)
+#define pipe_read(pipe, data, len) recv((pipe), (data), (len), 0)
 #undef WIN32_LEAN_AND_MEAN
+#else
+#define pipe_write(pipe, data, len) write((pipe), (data), (len))
+#define pipe_read(pipe, data, len) read((pipe), (data), (len))
 #endif
 
 #include "event.h"
@@ -76,7 +81,7 @@
     printf("Notify Called\n");
     if(del_notifier_status == NOTIFIER_READY) {
         printf("Notifying\n");
-        write(del_notifier[EVBUFFER_END], ".", 1);
+        printf("Notify: write returned %d\n", pipe_write(del_notifier[EVBUFFER_END], ".", 1));
         del_notifier_status = NOTIFIER_PENDING;
     }
 }
@@ -90,7 +95,7 @@
     printf("Delayed Callback Called\n");
     
     /* Read data out of socketpair */
-    readlen = read(fd, &readdata, 1);
+    readlen = pipe_read(fd, &readdata, 1);
     
     /* Set notifier status back to ready */
     del_notifier_status = NOTIFIER_READY;



More information about the tor-commits mailing list