[or-cvs] r10483: Changes for 4th June - See doc/plan.txt (in libevent-urz/trunk: . doc sample)

Urz at seul.org Urz at seul.org
Mon Jun 4 10:15:24 UTC 2007


Author: Urz
Date: 2007-06-04 06:15:24 -0400 (Mon, 04 Jun 2007)
New Revision: 10483

Modified:
   libevent-urz/trunk/buffer.c
   libevent-urz/trunk/doc/plan.txt
   libevent-urz/trunk/event.h
   libevent-urz/trunk/sample/Makefile.am
Log:
Changes for 4th June - See doc/plan.txt

Modified: libevent-urz/trunk/buffer.c
===================================================================
--- libevent-urz/trunk/buffer.c	2007-06-04 09:40:10 UTC (rev 10482)
+++ libevent-urz/trunk/buffer.c	2007-06-04 10:15:24 UTC (rev 10483)
@@ -57,6 +57,10 @@
 
 #include "event.h"
 
+int del_notifier_status = NOTIFIER_UNINIT;
+int del_notifier[2];
+static struct event evbuffer_del_event;
+
 struct evbuffer *
 evbuffer_new(void)
 {
@@ -454,3 +458,49 @@
 	buffer->cb = cb;
 	buffer->cbarg = cbarg;
 }
+
+/* Code to do setup / initialization of the evbuffer delayed callbacks 
+ * Initially copied from ev_signal_init, then modified.
+ */
+void evbuffer_del_init(void) 
+{
+    /* create the delayed notifier socketpair */
+	if (socketpair(AF_UNIX, SOCK_STREAM, 0, del_notifier) == -1)
+		event_err(1, "%s: socketpair", __func__);
+
+    /* 
+     * I don't understand what this does, and these declarations are in
+     * signal.c, so it is commented out until I do.
+	FD_CLOSEONEXEC(del_notifier[0]);
+	FD_CLOSEONEXEC(del_notifier[1]);
+     */
+
+    /* 
+     * If I'm not mistaken that means that calls to write on
+     * del_notifier[EVBUFFER_END] will be non-blocking
+     */
+	fcntl(del_notifier[EVBUFFER_END], F_SETFL, O_NONBLOCK);
+
+    
+	event_set(&evbuffer_del_event, del_notifier[DISPATCH_END], EV_READ,
+	    evsignal_cb, NULL);
+        /* &ev_signal); */
+    /* I can't find any documentation for this, what does it do? */
+	evbuffer_del_event.ev_flags |= EVLIST_INTERNAL;
+}
+
+void evbuffer_set_del_read_cb(struct evbuffer *buffer,
+    void (*del_read_event)(struct evbuffer *, void *),
+    void *del_read_event_arg) 
+{
+    buffer->del_read_event = del_read_event;
+    buffer->del_read_event_arg = del_read_event_arg;
+}
+
+void evbuffer_set_del_write_cb(struct evbuffer *buffer,
+    void (*del_write_event)(struct evbuffer *, void *),
+    void *del_write_event_arg) 
+{
+    buffer->del_write_event = del_write_event;
+    buffer->del_write_event_arg = del_write_event_arg;
+}
\ No newline at end of file

Modified: libevent-urz/trunk/doc/plan.txt
===================================================================
--- libevent-urz/trunk/doc/plan.txt	2007-06-04 09:40:10 UTC (rev 10482)
+++ libevent-urz/trunk/doc/plan.txt	2007-06-04 10:15:24 UTC (rev 10483)
@@ -18,28 +18,34 @@
 1 global socketpair, who has 1 read event which polls all evbuffers.
 evbuffers need to be made threadsafe...
 
-
 It it more generally useful than 1) or 3), and can stand alone better.
 
 Coding:
-Alter evbuffer (event.h:212) struct so it has a socketpair.
-Alter evbuffer new/free routines (buffer.c:61/71)to initialize/close socketpair.
-(On free/close we also need to remove the events for our socketpair)
-Add a new event_add / event_del etc which sets the read event for the event_loop half of the socketpair
+Alter evbuffer (event.h:212) struct.
+    - Mostly done. Place to store callbacks + their data, flags if callback should occur.
+    - Needs a mutex/lock added. Look at compat files to see if there is a type we can use.
+    
+Add a new event_add / event_del for delayed evbuffer events
 (so the user doesn't have to know about the socketpair trick).
-Write a new, simple function to be the evbuffer callback. This function needs to
-push something down the pipe to let the main-loop know an event has occured.
-('R'/'W')
+    - Done (evbuffer_set_del_read_cb and evbuffer_set_del_write_cb, buffer.c:492/500
+
+Alter the evbuffer functions (add, drain, etc) to use the mutex on the evbuffer struct,
+to set the evbuffer flags to let the main thread know callbacks are ready, and to call
+a function to ensure the main event-loop is notified of events.
+    - Not started
+    
 Write a short read event handler for the event_loop half of the socketpair which
 simply reads all there is to be read (no blocking!) and calls the real read/write callbacks
 depending on what it reads.
+    - Not started
 
-Nick...
-I know this is more complex than what we talked about, but we can't really check the write
-part of a socketpair with select. Originally my plan was to only check the read part.
-This seems to be OK from our perspective, until we get to parts 4)
-and 5), because tor's main event loop wants to know when data is ready to be written.
+TODOs for tomorrow:
+Adding the mutex to evbuffer
+Make a list of all evbuffers so our event_loop handler can look through it. 
+evbuffer create/destroy functions need to add/remove evbuffers from this list.
+Write event_loop handler.
 
+
 Testing:
 Add test cases to libevent testing code... test/regress.c I believe
 

Modified: libevent-urz/trunk/event.h
===================================================================
--- libevent-urz/trunk/event.h	2007-06-04 09:40:10 UTC (rev 10482)
+++ libevent-urz/trunk/event.h	2007-06-04 10:15:24 UTC (rev 10483)
@@ -219,8 +219,33 @@
 
 	void (*cb)(struct evbuffer *, size_t, size_t, void *);
 	void *cbarg;
+    
+    /* 
+     * Callback Function pointers for 'delayed' callback -
+     * That is, callbacks which occur at the next dispatch.
+     * 
+     * The Read event is called after data has been writen in,
+     * The Write event is called after data has been read out.
+     */
+    void (*del_read_event)(struct evbuffer *, void *);
+    void *del_read_event_arg;
+    
+    void (*del_write_event)(struct evbuffer *, void *);
+    void *del_write_event_arg;
+    
+    /* 1 if callback should occur, 0 if it should not */
+    u_char del_read_event_set;
+    u_char del_write_event_set;
 };
 
+extern u_char del_notifier_status;
+#define NOTIFIER_UNINIT 0
+#define NOTIFIER_READY 1
+#define NOTIFIER_PENDING 2
+extern int del_notifier[2];
+#define EVBUFFER_END 0
+#define DISPATCH_END 1
+
 /* Just for error reporting - use other constants otherwise */
 #define EVBUFFER_READ		0x01
 #define EVBUFFER_WRITE		0x02
@@ -290,6 +315,8 @@
 int evbuffer_read(struct evbuffer *, int, int);
 u_char *evbuffer_find(struct evbuffer *, const u_char *, size_t);
 void evbuffer_setcb(struct evbuffer *, void (*)(struct evbuffer *, size_t, size_t, void *), void *);
+void evbuffer_set_del_read_cb(struct evbuffer *, void (*)(struct evbuffer *, void *), void *);
+void evbuffer_set_del_write_cb(struct evbuffer *, void (*)(struct evbuffer *, void *), void *); 
 
 /* 
  * Marshaling tagged data - We assume that all tags are inserted in their

Modified: libevent-urz/trunk/sample/Makefile.am
===================================================================
--- libevent-urz/trunk/sample/Makefile.am	2007-06-04 09:40:10 UTC (rev 10482)
+++ libevent-urz/trunk/sample/Makefile.am	2007-06-04 10:15:24 UTC (rev 10483)
@@ -4,7 +4,8 @@
 CPPFPLAGS = -I.. 
 CFLAGS = -I../compat
 
-noinst_PROGRAMS = event-test time-test signal-test
+#noinst_PROGRAMS = event-test time-test signal-test
+noinst_PROGRAMS = time-test signal-test
 
 event_test_sources = event-test.c
 time_test_sources = time-test.c



More information about the tor-commits mailing list