commit 90fc8d36220c0d66c352ee5f72080b8592d310d5
Author: Ryan <ry@tinyclouds.org>
Date:   Tue Apr 28 22:37:03 2009 +0200

    Update liboi. Use EV_MULTIPLICITY=0.
    
    This might need to be changed in the future if ev is needed in thread pools
    or extension libraries. However for now it makes sense to just use a single
    loop.

diff --git a/deps/liboi/oi_socket.c b/deps/liboi/oi_socket.c
index f922d23..57dd3fa 100644
--- a/deps/liboi/oi_socket.c
+++ b/deps/liboi/oi_socket.c
@@ -11,6 +11,14 @@
 #include <ev.h>
 #include <oi_socket.h>
 
+#if EV_MULTIPLICITY
+# define SOCKET_LOOP_ socket->loop, 
+# define SERVER_LOOP_ server->loop, 
+#else
+# define SOCKET_LOOP_ 
+# define SERVER_LOOP_
+#endif // EV_MULTIPLICITY
+
 #if HAVE_GNUTLS
 # include <gnutls/gnutls.h>
 # define GNUTLS_NEED_WRITE (gnutls_record_get_direction(socket->session) == 1)
@@ -49,8 +57,8 @@ full_close(oi_socket *socket)
   socket->read_action = NULL;
   socket->write_action = NULL;
 
-  if(socket->loop) {
-    ev_feed_event(socket->loop, &socket->read_watcher, EV_READ);
+  if(socket->attached) {
+    ev_feed_event(SOCKET_LOOP_ &socket->read_watcher, EV_READ);
   }
   return OKAY;
 }
@@ -88,7 +96,7 @@ update_write_buffer_after_send(oi_socket *socket, ssize_t sent)
     }  
 
     if(oi_queue_empty(&socket->out_stream)) {
-      ev_io_stop(socket->loop, &socket->write_watcher);
+      ev_io_stop(SOCKET_LOOP_ &socket->write_watcher);
       if(socket->on_drain)
         socket->on_drain(socket);
     }
@@ -160,7 +168,7 @@ secure_socket_send(oi_socket *socket)
   ssize_t sent;
 
   if(oi_queue_empty(&socket->out_stream)) {
-    ev_io_stop(socket->loop, &socket->write_watcher);
+    ev_io_stop(SOCKET_LOOP_ &socket->write_watcher);
     return AGAIN;
   }
 
@@ -337,7 +345,7 @@ socket_send(oi_socket *socket)
   assert(socket->secure == FALSE);
 
   if(oi_queue_empty(&socket->out_stream)) {
-    ev_io_stop(socket->loop, &socket->write_watcher);
+    ev_io_stop(SOCKET_LOOP_ &socket->write_watcher);
     return AGAIN;
   }
 
@@ -477,14 +485,16 @@ assign_file_descriptor(oi_socket *socket, int fd)
  * Called by server->connection_watcher.
  */
 static void 
-on_connection(struct ev_loop *loop, ev_io *watcher, int revents)
+on_connection(EV_P_ ev_io *watcher, int revents)
 {
   oi_server *server = watcher->data;
 
  // printf("on connection!\n");
 
   assert(server->listening);
+#if EV_MULTIPLICITY
   assert(server->loop == loop);
+#endif 
   assert(&server->connection_watcher == watcher);
   
   if(EV_ERROR & revents) {
@@ -524,7 +534,7 @@ on_connection(struct ev_loop *loop, ev_io *watcher, int revents)
 
   socket->server = server;
   assign_file_descriptor(socket, fd);
-  oi_socket_attach(socket, loop);
+  oi_socket_attach(EV_A_ socket);
 }
 
 int
@@ -595,23 +605,30 @@ oi_server_close(oi_server *server)
 }
 
 void
-oi_server_attach (oi_server *server, struct ev_loop *loop)
+oi_server_attach (EV_P_ oi_server *server)
 {
-  ev_io_start (loop, &server->connection_watcher);
+  ev_io_start (EV_A_ &server->connection_watcher);
+#if EV_MULTIPLICITY
   server->loop = loop;
+#endif
+  server->attached = TRUE;
 }
 
 void
 oi_server_detach (oi_server *server)
 {
-  ev_io_stop (server->loop, &server->connection_watcher);
+  ev_io_stop (SERVER_LOOP_ &server->connection_watcher);
+#if EV_MULTIPLICITY
   server->loop = NULL;
+#endif
+  server->attached = FALSE;
 }
 
 void 
 oi_server_init(oi_server *server, int backlog)
 {
   server->backlog = backlog;
+  server->attached = FALSE;
   server->listening = FALSE;
   server->fd = -1;
   server->connection_watcher.data = server;
@@ -624,7 +641,7 @@ oi_server_init(oi_server *server, int backlog)
 
 /* Internal callback. called by socket->timeout_watcher */
 static void 
-on_timeout(struct ev_loop *loop, ev_timer *watcher, int revents)
+on_timeout(EV_P_ ev_timer *watcher, int revents)
 {
   oi_socket *socket = watcher->data;
 
@@ -652,7 +669,7 @@ release_write_buffer(oi_socket *socket)
 
 /* Internal callback. called by socket->read_watcher */
 static void 
-on_io_event(struct ev_loop *loop, ev_io *watcher, int revents)
+on_io_event(EV_P_ ev_io *watcher, int revents)
 {
   oi_socket *socket = watcher->data;
 
@@ -698,9 +715,9 @@ on_io_event(struct ev_loop *loop, ev_io *watcher, int revents)
 close:
   release_write_buffer(socket);
 
-  ev_clear_pending (socket->loop, &socket->write_watcher);
-  ev_clear_pending (socket->loop, &socket->read_watcher);
-  ev_clear_pending (socket->loop, &socket->timeout_watcher);
+  ev_clear_pending (EV_A_ &socket->write_watcher);
+  ev_clear_pending (EV_A_ &socket->read_watcher);
+  ev_clear_pending (EV_A_ &socket->timeout_watcher);
 
   oi_socket_detach(socket);
 
@@ -721,7 +738,10 @@ oi_socket_init(oi_socket *socket, float timeout)
 {
   socket->fd = -1;
   socket->server = NULL;
+#if EV_MULTIPLICITY
   socket->loop = NULL;
+#endif
+  socket->attached = FALSE;
   socket->connected = FALSE;
 
   oi_queue_init(&socket->out_stream);
@@ -765,8 +785,8 @@ oi_socket_write_eof (oi_socket *socket)
       ) 
     {
       socket->write_action = secure_half_goodbye;
-      if(socket->loop)
-        ev_io_start(socket->loop, &socket->write_watcher);
+      if(socket->attached)
+        ev_io_start(SOCKET_LOOP_ &socket->write_watcher);
       return;
     }
     /* secure servers cannot handle half-closed connections? */
@@ -799,8 +819,8 @@ oi_socket_close (oi_socket *socket)
       socket->read_action = NULL;
     }
 
-    if(socket->loop)
-      ev_io_start(socket->loop, &socket->write_watcher);
+    if(socket->attached)
+      ev_io_start(SOCKET_LOOP_ &socket->write_watcher);
 
     return;
   }
@@ -815,7 +835,7 @@ oi_socket_close (oi_socket *socket)
 void 
 oi_socket_reset_timeout(oi_socket *socket)
 {
-  ev_timer_again(socket->loop, &socket->timeout_watcher);
+  ev_timer_again(SOCKET_LOOP_ &socket->timeout_watcher);
 }
 
 /**
@@ -831,7 +851,8 @@ oi_socket_write(oi_socket *socket, oi_buf *buf)
   oi_queue_insert_head(&socket->out_stream, &buf->queue);
 
   buf->written = 0;
-  ev_io_start(socket->loop, &socket->write_watcher);
+  // XXX if (socket->attached)   ??
+  ev_io_start(SOCKET_LOOP_ &socket->write_watcher);
 }
 
 static void
@@ -856,45 +877,51 @@ oi_socket_write_simple(oi_socket *socket, const char *str, size_t len)
 }
 
 void
-oi_socket_attach(oi_socket *socket, struct ev_loop *loop)
+oi_socket_attach(EV_P_ oi_socket *socket)
 {
+#if EV_MULTIPLICITY
   socket->loop = loop;
+#endif 
+  socket->attached = TRUE;
 
-  ev_timer_again(loop, &socket->timeout_watcher);
+  ev_timer_again(EV_A_ &socket->timeout_watcher);
 
   if(socket->read_action) 
-    ev_io_start(loop, &socket->read_watcher);
+    ev_io_start(EV_A_ &socket->read_watcher);
 
   if(socket->write_action) 
-    ev_io_start(loop, &socket->write_watcher);
+    ev_io_start(EV_A_ &socket->write_watcher);
 
   /* make sure the io_event happens soon  in the case we're being reattached */
-  ev_feed_event(loop, &socket->read_watcher, EV_READ);
+  ev_feed_event(EV_A_ &socket->read_watcher, EV_READ);
 }
 
 void
 oi_socket_detach(oi_socket *socket)
 {
-  if(socket->loop) {
-    ev_io_stop(socket->loop, &socket->write_watcher);
-    ev_io_stop(socket->loop, &socket->read_watcher);
-    ev_timer_stop(socket->loop, &socket->timeout_watcher);
+  if(socket->attached) {
+    ev_io_stop(SOCKET_LOOP_ &socket->write_watcher);
+    ev_io_stop(SOCKET_LOOP_ &socket->read_watcher);
+    ev_timer_stop(SOCKET_LOOP_ &socket->timeout_watcher);
+#if EV_MULTIPLICITY
     socket->loop = NULL;
+#endif
+    socket->attached = FALSE;
   }
 }
 
 void
 oi_socket_read_stop (oi_socket *socket)
 {
-  ev_io_stop(socket->loop, &socket->read_watcher);
-  ev_clear_pending (socket->loop, &socket->read_watcher);
+  ev_io_stop(SOCKET_LOOP_ &socket->read_watcher);
+  ev_clear_pending (SOCKET_LOOP_ &socket->read_watcher);
 }
 
 void
 oi_socket_read_start (oi_socket *socket)
 {
   if(socket->read_action) {
-    ev_io_start(socket->loop, &socket->read_watcher);
+    ev_io_start(SOCKET_LOOP_ &socket->read_watcher);
     /* XXX feed event? */
   }
 }
