SOURCES: tpop3d-libevent.patch - updated; don't watch EV_WRITE eve...

arekm arekm at pld-linux.org
Sat Jun 3 18:10:55 CEST 2006


Author: arekm                        Date: Sat Jun  3 16:10:55 2006 GMT
Module: SOURCES                       Tag: HEAD
---- Log message:
- updated; don't watch EV_WRITE events by defaults; fire them up only when needed

---- Files affected:
SOURCES:
   tpop3d-libevent.patch (1.1 -> 1.2) 

---- Diffs:

================================================================
Index: SOURCES/tpop3d-libevent.patch
diff -u SOURCES/tpop3d-libevent.patch:1.1 SOURCES/tpop3d-libevent.patch:1.2
--- SOURCES/tpop3d-libevent.patch:1.1	Fri Jun  2 11:12:38 2006
+++ SOURCES/tpop3d-libevent.patch	Sat Jun  3 18:10:49 2006
@@ -12,21 +12,30 @@
  dnl The various authentication options.
 diff -urN tpop3d-1.5.3.org/connection.c tpop3d-1.5.3/connection.c
 --- tpop3d-1.5.3.org/connection.c	2006-06-02 10:37:54.000000000 +0200
-+++ tpop3d-1.5.3/connection.c	2006-06-02 11:02:44.000000000 +0200
++++ tpop3d-1.5.3/connection.c	2006-06-03 13:00:02.000000000 +0200
 @@ -38,6 +38,8 @@
  
  extern int verbose;
  
-+extern connection_post_event(int fd, short event_type, void *vc);
++extern void connection_post_event(int fd, short event_type, void *vc);
 +
  /* make_timestamp:
   * Create a timestamp string. */
  #define TIMESTAMP_LEN   32
+@@ -93,7 +95,7 @@
+ /* connection_new:
+  * Create a connection object from a socket. */
+ connection connection_new(int s, const struct sockaddr_in *sin, listener L) {
+-    int n;
++    ssize_t n;
+     connection c = NULL;
+ 
+     alloc_struct(_connection, c);
 @@ -143,6 +145,12 @@
  #endif
      c->io = (struct ioabs*)ioabs_tcp_create();
      
-+    event_set(&c->ev, c->s, EV_READ|EV_WRITE|EV_PERSIST, connection_post_event, (void *)c);
++    event_set(&c->ev, c->s, EV_READ|EV_PERSIST, connection_post_event, (void *)c);
 +    if (event_add(&c->ev, NULL) == -1) {
 +	    log_print(LOG_ERR, "connection_new: event_add: %m");
 +	    goto fail;
@@ -46,7 +55,7 @@
  
 diff -urN tpop3d-1.5.3.org/connection.h tpop3d-1.5.3/connection.h
 --- tpop3d-1.5.3.org/connection.h	2003-01-09 23:59:37.000000000 +0100
-+++ tpop3d-1.5.3/connection.h	2006-06-02 11:02:44.000000000 +0200
++++ tpop3d-1.5.3/connection.h	2006-06-03 14:23:41.000000000 +0200
 @@ -35,6 +35,7 @@
  
  typedef struct _connection {
@@ -55,18 +64,14 @@
      struct sockaddr_in sin; /* name of peer                     */
      char *remote_ip;        /* ASCII remote IP address          */
      struct sockaddr_in sin_local; /* name of local side         */
-@@ -83,19 +84,11 @@
-      * IOABS_ERROR if a fatal error occurred. */
-     ssize_t (*immediate_write)(connection c, const void *buf, size_t count);
- 
--    /* pre_ and post_select are called before and after select(2) in the main
--     * loop, and should do all I/O related processing. Frozen connection
--     * handling is done in the calling code, so these should address only
--     * buffering and state issues. post_select should return a combination of
--     * the flags defined below, as well as doing any I/O-layer specific
--     * handling. */
+@@ -89,13 +90,13 @@
+      * buffering and state issues. post_select should return a combination of
+      * the flags defined below, as well as doing any I/O-layer specific
+      * handling. */
 -    void (*pre_select)(connection c, int *n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds);
 -    
++    short (*pre_event)(connection c);
++
      /* post_select:
       * Do handling after select has completed. Returns 1 if new data have been
       * read, 0 if not. May alter the connection_state of the associated
@@ -78,7 +83,7 @@
       * Shut down the connection. Returns zero on success, IOABS_WOULDBLOCK if
 diff -urN tpop3d-1.5.3.org/ioabs_tcp.c tpop3d-1.5.3/ioabs_tcp.c
 --- tpop3d-1.5.3.org/ioabs_tcp.c	2003-09-30 20:45:46.000000000 +0200
-+++ tpop3d-1.5.3/ioabs_tcp.c	2006-06-02 11:02:44.000000000 +0200
++++ tpop3d-1.5.3/ioabs_tcp.c	2006-06-03 14:23:59.000000000 +0200
 @@ -25,6 +25,7 @@
  /* ioabs_tcp_shutdown:
   * Shut down the socket connection. */
@@ -87,24 +92,27 @@
      shutdown(c->s, 2);
      close(c->s);
      c->cstate = closed;
-@@ -59,29 +60,16 @@
-         return n;
- }
+@@ -61,27 +62,27 @@
  
--/* ioabs_tcp_pre_select:
-- * Simple pre-select handling for TCP. */
+ /* ioabs_tcp_pre_select:
+  * Simple pre-select handling for TCP. */
 -static void ioabs_tcp_pre_select(connection c, int *n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds) {
--    struct ioabs_tcp *io;
--    io = (struct ioabs_tcp*)c->io;
--
++static short ioabs_tcp_pre_event(connection c) {
+     struct ioabs_tcp *io;
++    short want_event = EV_READ; /* always want to read */
+     io = (struct ioabs_tcp*)c->io;
+ 
 -    FD_SET(c->s, readfds);
--    if (buffer_available(c->wrb) > 0)
+     if (buffer_available(c->wrb) > 0)
 -        FD_SET(c->s, writefds);
 -    
 -    if (c->s > *n)
 -        *n = c->s;
--}
--
++	    want_event |= EV_WRITE;
++
++    return want_event;
+ }
+ 
 -/* ioabs_tcp_post_select:
 +/* ioabs_tcp_post_event:
   * Simple post-select handling for TCP. */
@@ -121,7 +129,7 @@
          /* Can read data. */
          do {
              char *r;
-@@ -110,7 +98,7 @@
+@@ -110,7 +111,7 @@
          }
      }
  
@@ -130,19 +138,20 @@
          /* Can write data. */
          n = 1;
          do {
-@@ -149,8 +137,7 @@
+@@ -149,8 +150,8 @@
      struct ioabs_tcp *io;
      io = xmalloc(sizeof *io);
      io->und.immediate_write = ioabs_tcp_immediate_write;
 -    io->und.pre_select      = ioabs_tcp_pre_select;
 -    io->und.post_select     = ioabs_tcp_post_select;
-+    io->und.post_event = ioabs_tcp_post_event;
++    io->und.pre_event       = ioabs_tcp_pre_event;
++    io->und.post_event      = ioabs_tcp_post_event;
      io->und.shutdown        = ioabs_tcp_shutdown;
      io->und.destroy         = ioabs_tcp_destroy;
      return io;
 diff -urN tpop3d-1.5.3.org/ioabs_tls.c tpop3d-1.5.3/ioabs_tls.c
 --- tpop3d-1.5.3.org/ioabs_tls.c	2006-06-02 10:37:54.000000000 +0200
-+++ tpop3d-1.5.3/ioabs_tls.c	2006-06-02 11:02:44.000000000 +0200
++++ tpop3d-1.5.3/ioabs_tls.c	2006-06-03 14:40:32.000000000 +0200
 @@ -44,6 +44,7 @@
  /* underlying_shutdown CONNECTION
   * Shut down the underlying transport for CONNECTION. */
@@ -151,26 +160,28 @@
      shutdown(c->s, 2);
      close(c->s);
      c->s = -1;
-@@ -226,33 +227,18 @@
-     return IOABS_ERROR;
- }
+@@ -228,32 +229,32 @@
  
--/* ioabs_tls_pre_select:
-- * Pre-select handling for TLS, taking account of the rehandshaking nonsense. */
+ /* ioabs_tls_pre_select:
+  * Pre-select handling for TLS, taking account of the rehandshaking nonsense. */
 -static void ioabs_tls_pre_select(connection c, int *n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds) {
--    struct ioabs_tls *io;
--    io = (struct ioabs_tls*)c->io;
--
++static short ioabs_tls_pre_event(connection c) {
+     struct ioabs_tls *io;
+     io = (struct ioabs_tls*)c->io;
++    short want_event = EV_READ; /* always want to read */
+ 
 -    FD_SET(c->s, readfds);  /* always want to read */
--    if (!io->write_blocked_on_read &&
--        (buffer_available(c->wrb) > 0 || io->accept_blocked_on_write
--         || io->read_blocked_on_write || io->shutdown_blocked_on_write))
+     if (!io->write_blocked_on_read &&
+         (buffer_available(c->wrb) > 0 || io->accept_blocked_on_write
+          || io->read_blocked_on_write || io->shutdown_blocked_on_write))
 -        FD_SET(c->s, writefds);
--
++	    want_event |= EV_WRITE;
+ 
 -    if (c->s > *n)
 -        *n = c->s;
--}
--
++    return want_event;
+ }
+ 
 -/* ioabs_tls_post_select:
 +/* ioabs_tls_post_event:
   * Post-select handling for TLS, with its complicated logic. */
@@ -185,24 +196,27 @@
  
 -    canread  = FD_ISSET(c->s, readfds);
 -    canwrite = FD_ISSET(c->s, writefds);
+-    
 +    canread  = event_type & EV_READ;
 +    canwrite = event_type & EV_WRITE;
-     
++
      /* First, accept handling. */
      if ((io->accept_blocked_on_read && canread) || (io->accept_blocked_on_write && canwrite)) {
-@@ -399,8 +385,7 @@
+         int e;
+@@ -399,8 +400,8 @@
          }
      
      io->und.immediate_write = ioabs_tls_immediate_write;
 -    io->und.pre_select      = ioabs_tls_pre_select;
 -    io->und.post_select     = ioabs_tls_post_select;
++    io->und.pre_event       = ioabs_tls_pre_event;
 +    io->und.post_event      = ioabs_tls_post_event;
      io->und.shutdown        = ioabs_tls_shutdown;
      io->und.destroy         = ioabs_tls_destroy;
  
 diff -urN tpop3d-1.5.3.org/listener.c tpop3d-1.5.3/listener.c
 --- tpop3d-1.5.3.org/listener.c	2003-11-14 19:08:29.000000000 +0100
-+++ tpop3d-1.5.3/listener.c	2006-06-02 11:02:44.000000000 +0200
++++ tpop3d-1.5.3/listener.c	2006-06-02 11:10:25.000000000 +0200
 @@ -42,6 +42,8 @@
  
  #include "util.h"
@@ -234,7 +248,7 @@
      if (L->have_re)
 diff -urN tpop3d-1.5.3.org/listener.h tpop3d-1.5.3/listener.h
 --- tpop3d-1.5.3.org/listener.h	2003-01-09 23:59:37.000000000 +0100
-+++ tpop3d-1.5.3/listener.h	2006-06-02 11:02:44.000000000 +0200
++++ tpop3d-1.5.3/listener.h	2006-06-02 11:10:25.000000000 +0200
 @@ -12,6 +12,8 @@
  #define __LISTENER_H_
  
@@ -252,10 +266,22 @@
  } *listener;
  
  /* the arguments of the constructor vary according to the particular
+diff -urN tpop3d-1.5.3.org/maildir.c tpop3d-1.5.3/maildir.c
+--- tpop3d-1.5.3.org/maildir.c	2006-06-02 10:37:54.000000000 +0200
++++ tpop3d-1.5.3/maildir.c	2006-06-02 11:10:25.000000000 +0200
+@@ -360,7 +360,7 @@
+ 
+     gettimeofday(&tv2, NULL);
+     f = (float)(tv2.tv_sec - tv1.tv_sec) + 1e-6 * (float)(tv2.tv_usec - tv1.tv_usec);
+-    log_print(LOG_DEBUG, "maildir_new: scanned maildir %s (%d messages) in %0.3fs", dirname, (int)M->num, f);
++    log_print(LOG_NOTICE, "maildir_new: scanned maildir %s (%d messages) in %0.3fs", dirname, (int)M->num, f);
+     
+     return M;
+ 
 diff -urN tpop3d-1.5.3.org/main.c tpop3d-1.5.3/main.c
 --- tpop3d-1.5.3.org/main.c	2006-06-02 10:37:54.000000000 +0200
-+++ tpop3d-1.5.3/main.c	2006-06-02 11:02:44.000000000 +0200
-@@ -473,6 +473,9 @@
++++ tpop3d-1.5.3/main.c	2006-06-02 11:10:25.000000000 +0200
+@@ -473,6 +483,9 @@
          }
      }
  
@@ -267,7 +293,7 @@
      s = config_get_string("listen-address");
 diff -urN tpop3d-1.5.3.org/netloop.c tpop3d-1.5.3/netloop.c
 --- tpop3d-1.5.3.org/netloop.c	2006-06-02 10:37:54.000000000 +0200
-+++ tpop3d-1.5.3/netloop.c	2006-06-02 11:03:12.000000000 +0200
++++ tpop3d-1.5.3/netloop.c	2006-06-03 18:00:03.000000000 +0200
 @@ -30,6 +30,7 @@
  
  #include <sys/socket.h>
@@ -276,7 +302,16 @@
  
  #include "config.h"
  #include "connection.h"
-@@ -67,10 +68,9 @@
+@@ -38,6 +39,8 @@
+ #include "stringmap.h"
+ #include "util.h"
+ 
++void connection_post_event(int fd, short event_type, void *vc);
++
+ /* The socket send buffer is set to this, so that we don't end up in a
+  * position that we send so much data that the client will not have received
+  * all of it before we time them out. */
+@@ -67,10 +70,9 @@
  
  /* 
   * Theory of operation:
@@ -290,7 +325,7 @@
   * client, fork_child is called. The global variables listeners and
   * connections are used to handle this procedure.
   */
-@@ -103,25 +103,11 @@
+@@ -103,25 +105,11 @@
          if (*J == c) *J = NULL;
  }
  
@@ -318,7 +353,7 @@
              struct sockaddr_in sin, sinlocal;
              size_t l = sizeof(sin);
              static int tcp_send_buf = -1;
-@@ -185,20 +171,8 @@
+@@ -185,19 +173,39 @@
  
              if (errno != EAGAIN && errno != EINTR)
                  log_print(LOG_ERR, "net_loop: accept: %m");
@@ -330,16 +365,44 @@
 -/* connections_pre_select:
 - * Called before the main select(2) so connections can be polled. */
 -static void connections_pre_select(int *n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds) {
--    connection *J;
++/* connections_pre_event:
++ * reschedule some events */
++static void connections_pre_event(int fd, short event_type, void *arg) {
+     connection *J;
 -    for (J = connections; J < connections + max_connections; ++J)
--        /* Don't add frozen connections to the select masks. */
++    short want_event;
++    struct event *ev = arg;
++    struct timeval tv = {0};
++
++    for (J = connections; J < connections + max_connections; ++J) {
++       connection c = *J;
+         /* Don't add frozen connections to the select masks. */
 -        if (*J && !connection_isfrozen(*J) && (*J)->cstate != closed)
 -            (*J)->io->pre_select(*J, n, readfds, writefds, exceptfds);
--}
++       if (c && !connection_isfrozen(c) && c->cstate != closed) {
++            want_event = c->io->pre_event(c);
++	    /* update if required events are not pending */
++	    if ((want_event & EV_READ && !event_pending(&c->ev, EV_READ, NULL)) 
++			    || (want_event & EV_WRITE && !event_pending(&c->ev, EV_WRITE, NULL))) {
++		    event_del(&c->ev);
++		    event_set(&c->ev, (*J)->s, want_event|EV_PERSIST, connection_post_event, (void *)c);
++		    if (event_add(&c->ev, NULL) == -1)
++			    log_print(LOG_ERR, "connections_pre_event: event_add: %m");
++	    }
++       }
++    }
++
++    if (!evtimer_pending(ev, &tv)) {
++	    tv.tv_sec = 1;  /* must be smaller than timeout */
++	    evtimer_del(ev);
++	    evtimer_set(ev, connections_pre_event, (void *)ev);
++	    evtimer_add(ev, &tv);
++    }
++
+ }
  
  /* fork_child CONNECTION
-  * Handle forking a child to handle CONNECTION after authentication. Returns 1
-@@ -380,27 +354,13 @@
+@@ -380,27 +388,13 @@
   * running/closing/closed state machine around and reading and writing the I/O
   * buffers. We need to try to parse commands when it's indicated that data have
   * been read, and react to the changed state of any connection. */
@@ -354,7 +417,7 @@
 -        connection c;
 +void connection_post_event(int fd, short event_type, void *vc) {
          int r;
- 
+-
 -        if (!(c = connections[i]))
 -            continue;
 -
@@ -362,19 +425,23 @@
 -            connections[0] = c;
 -            connections[i] = NULL;
 -        }
++	
 +	connection c = vc;
  
          /* Handle all post-select I/O. */
 -        r = c->io->post_select(c, readfds, writefds, exceptfds);
-+	r = c->io->post_event(fd, event_type, vc);
++	r = c->io->post_event(fd, event_type, c);
  
          if (r && !connection_isfrozen(c)) {
              /*
-@@ -439,19 +399,11 @@
+@@ -438,20 +432,12 @@
+ 
                  if (!c || c->do_shutdown)
                      break;
-             }
--
+-            }
++	    }
++	}
+ 
 -            if (post_fork) {
 -                if (i != 0) {
 -                    connections[0] = connections[i];
@@ -382,19 +449,23 @@
 -                }
 -                i = 0;
 -                break;
-             }
- 
-+	/* if connection has been destroyed, return */
-             if (!c)
+-            }
+-
+-            if (!c)
 -                continue; /* if connection has been destroyed, do next one */
 -        }
++	/* if connection has been destroyed, return */
++	if (!c)
 +		return;
  
          /* Timeout handling. */
          if (timeout_seconds && (time(NULL) > (c->idlesince + timeout_seconds))) {
-@@ -499,19 +451,12 @@
+@@ -497,21 +483,14 @@
+                 }
+                 log_print(LOG_INFO, _("connections_post_select: client %s: finished session for `%s' with %s"), c->idstr, c->a->user, c->a->auth);
              }
-             log_print(LOG_INFO, _("connections_post_select: client %s: disconnected; %d/%d bytes read/written"), c->idstr, c->nrd, c->nwr);
+-            log_print(LOG_INFO, _("connections_post_select: client %s: disconnected; %d/%d bytes read/written"), c->idstr, c->nrd, c->nwr);
++            log_print(LOG_NOTICE, _("connections_post_select: client %s: disconnected; %d/%d bytes read/written"), c->idstr, c->nrd, c->nwr);
  
 -/*            remove_connection(c);*/
 -            connections[i] = NULL;
@@ -413,19 +484,32 @@
  }
  
  /* net_loop
-@@ -520,6 +465,7 @@
+@@ -520,6 +499,7 @@
  sig_atomic_t foad = 0, restart = 0; /* Flags used to indicate that we should exit or should re-exec. */
  
  void net_loop(void) {
-+	extern int (*event_sigcb)(void);
++    extern int (*event_sigcb)(void);
      connection *J;
  #ifdef AUTH_OTHER
      extern pid_t auth_other_childdied;
-@@ -538,31 +484,12 @@
+@@ -528,6 +508,8 @@
+     extern pid_t child_died;
+     extern int child_died_signal;
+     sigset_t chmask;
++    struct event ev;
++    struct timeval tv = {0};
+     
+     sigemptyset(&chmask);
+     sigaddset(&chmask, SIGCHLD);
+@@ -537,32 +519,16 @@
+     connections = (connection*)xcalloc(max_connections, sizeof(connection*));
  
      log_print(LOG_INFO, _("net_loop: tpop3d version %s successfully started"), TPOP3D_VERSION);
++
++    tv.tv_sec = 1;  /* must be smaller than timeout */
++    evtimer_set(&ev, connections_pre_event, (void *)&ev);
++    evtimer_add(&ev, &tv);
      
-+    
      /* Main select() loop */
      while (!foad) {
 -        fd_set readfds, writefds;
@@ -436,9 +520,9 @@
 -        FD_ZERO(&writefds);
 -
 -        tv.tv_sec = 1;  /* must be smaller than timeout */
--
--        if (!post_fork) listeners_pre_select(&n, &readfds, &writefds, NULL);
  
+-        if (!post_fork) listeners_pre_select(&n, &readfds, &writefds, NULL);
+-
 -        connections_pre_select(&n, &readfds, &writefds, NULL);
 -
 -        e = select(n + 1, &readfds, &writefds, NULL, &tv);
@@ -452,13 +536,13 @@
 -            connections_post_select(&readfds, &writefds, NULL);
 -        }
 +    	event_sigcb = event_sigcb_handler;
-+		event_dispatch();
++	event_dispatch();
  
          sigprocmask(SIG_BLOCK, &chmask, NULL);
          
 diff -urN tpop3d-1.5.3.org/signals.c tpop3d-1.5.3/signals.c
 --- tpop3d-1.5.3.org/signals.c	2003-07-18 10:26:00.000000000 +0200
-+++ tpop3d-1.5.3/signals.c	2006-06-02 11:02:44.000000000 +0200
++++ tpop3d-1.5.3/signals.c	2006-06-02 11:10:25.000000000 +0200
 @@ -95,6 +95,9 @@
  /* terminate_signal_handler:
   * Signal handler to handle orderly termination of the program. */
@@ -513,7 +597,7 @@
  
 diff -urN tpop3d-1.5.3.org/signals.h tpop3d-1.5.3/signals.h
 --- tpop3d-1.5.3.org/signals.h	2003-01-09 23:59:39.000000000 +0100
-+++ tpop3d-1.5.3/signals.h	2006-06-02 11:02:44.000000000 +0200
++++ tpop3d-1.5.3/signals.h	2006-06-02 11:10:25.000000000 +0200
 @@ -17,5 +17,6 @@
  void die_signal_handler(const int i);
  void child_signal_handler(const int i);
================================================================

---- CVS-web:
    http://cvs.pld-linux.org/SOURCES/tpop3d-libevent.patch?r1=1.1&r2=1.2&f=u



More information about the pld-cvs-commit mailing list