Revert "s3:events: Call all ready fd event handlers on each iteration of the main...
authorStefan Metzmacher <metze@samba.org>
Mon, 24 Jan 2011 07:47:38 +0000 (08:47 +0100)
committerStefan Metzmacher <metze@samba.org>
Mon, 31 Jan 2011 15:16:09 +0000 (16:16 +0100)
This reverts commit 455fccf86b6544cd17a2571c63a88f8aebff3f74.

I'll add a more generic fix for this problem.

metze

source3/include/event.h
source3/lib/events.c
source3/nmbd/nmbd_packets.c
source3/smbd/process.c
source3/winbindd/winbindd_dual.c

index 101a967c47e191672c059c2d6e8b27234bab7376..dc45b768963aa855e53b64ec12fc39195f0666ad 100644 (file)
@@ -30,7 +30,7 @@ bool event_add_to_select_args(struct event_context *event_ctx,
                              fd_set *read_fds, fd_set *write_fds,
                              struct timeval *timeout, int *maxfd);
 bool run_events(struct event_context *event_ctx,
-               int *selrtn, fd_set *read_fds, fd_set *write_fds);
+               int selrtn, fd_set *read_fds, fd_set *write_fds);
 struct timeval *get_timed_events_timeout(struct event_context *event_ctx,
                                         struct timeval *to_ret);
 void dump_event_list(struct event_context *event_ctx);
index d987072884d361aed67b150582c2ea29fbbaa60e..7670eb1f10d3f9dc88d6464d27deaea532b8a9fc 100644 (file)
@@ -68,7 +68,7 @@ bool event_add_to_select_args(struct tevent_context *ev,
 }
 
 bool run_events(struct tevent_context *ev,
-               int *selrtn, fd_set *read_fds, fd_set *write_fds)
+               int selrtn, fd_set *read_fds, fd_set *write_fds)
 {
        struct tevent_fd *fde;
        struct timeval now;
@@ -113,7 +113,7 @@ bool run_events(struct tevent_context *ev,
                return true;
        }
 
-       if (*selrtn <= 0) {
+       if (selrtn == 0) {
                /*
                 * No fd ready
                 */
@@ -123,16 +123,8 @@ bool run_events(struct tevent_context *ev,
        for (fde = ev->fd_events; fde; fde = fde->next) {
                uint16 flags = 0;
 
-               if (FD_ISSET(fde->fd, read_fds)) {
-                       flags |= EVENT_FD_READ;
-                       FD_CLR(fde->fd, read_fds);
-                       (*selrtn)--;
-               }
-               if (FD_ISSET(fde->fd, write_fds)) {
-                       flags |= EVENT_FD_WRITE;
-                       FD_CLR(fde->fd, write_fds);
-                       (*selrtn)--;
-               }
+               if (FD_ISSET(fde->fd, read_fds)) flags |= EVENT_FD_READ;
+               if (FD_ISSET(fde->fd, write_fds)) flags |= EVENT_FD_WRITE;
 
                if (flags & fde->flags) {
                        fde->handler(ev, fde, flags, fde->private_data);
@@ -171,7 +163,7 @@ static int s3_event_loop_once(struct tevent_context *ev, const char *location)
        struct timeval to;
        fd_set r_fds, w_fds;
        int maxfd = 0;
-       int ret = 0;
+       int ret;
 
        FD_ZERO(&r_fds);
        FD_ZERO(&w_fds);
@@ -179,7 +171,7 @@ static int s3_event_loop_once(struct tevent_context *ev, const char *location)
        to.tv_sec = 9999;       /* Max timeout */
        to.tv_usec = 0;
 
-       if (run_events(ev, &ret, NULL, NULL)) {
+       if (run_events(ev, 0, NULL, NULL)) {
                return 0;
        }
 
@@ -196,7 +188,7 @@ static int s3_event_loop_once(struct tevent_context *ev, const char *location)
                return -1;
        }
 
-       run_events(ev, &ret, &r_fds, &w_fds);
+       run_events(ev, ret, &r_fds, &w_fds);
        return 0;
 }
 
index 73ee1411046eaf01fe0f9c7ca290645fc172dcb2..48d10cc26dd484dbb8483041da5cce24f080a011 100644 (file)
@@ -1857,7 +1857,7 @@ bool listen_for_packets(bool run_election)
 
        fd_set r_fds;
        fd_set w_fds;
-       int selrtn = 0;
+       int selrtn;
        struct timeval timeout;
 #ifndef SYNC_DNS
        int dns_fd;
@@ -1884,7 +1884,7 @@ bool listen_for_packets(bool run_election)
 #endif
 
        /* Process a signal and timer events now... */
-       if (run_events(nmbd_event_context(), &selrtn, NULL, NULL)) {
+       if (run_events(nmbd_event_context(), 0, NULL, NULL)) {
                return False;
        }
 
@@ -1903,7 +1903,7 @@ bool listen_for_packets(bool run_election)
 
        selrtn = sys_select(maxfd+1,&r_fds,&w_fds,NULL,&timeout);
 
-       if (run_events(nmbd_event_context(), &selrtn, &r_fds, &w_fds)) {
+       if (run_events(nmbd_event_context(), selrtn, &r_fds, &w_fds)) {
                return False;
        }
 
index 12ea28a3992cdb9c45261113eac31aab3f7bdb4b..04ea747564a72c7fa84fa013e349d9df8cc37b3a 100644 (file)
@@ -963,7 +963,7 @@ void smbd_setup_sig_hup_handler(struct tevent_context *ev,
 static NTSTATUS smbd_server_connection_loop_once(struct smbd_server_connection *conn)
 {
        fd_set r_fds, w_fds;
-       int selrtn = 0;
+       int selrtn;
        struct timeval to;
        int maxfd = 0;
 
@@ -986,7 +986,7 @@ static NTSTATUS smbd_server_connection_loop_once(struct smbd_server_connection *
                                 &r_fds, &w_fds, &to, &maxfd);
 
        /* Process a signal and timed events now... */
-       if (run_events(smbd_event_context(), &selrtn, NULL, NULL)) {
+       if (run_events(smbd_event_context(), 0, NULL, NULL)) {
                return NT_STATUS_RETRY;
        }
 
@@ -1003,23 +1003,26 @@ static NTSTATUS smbd_server_connection_loop_once(struct smbd_server_connection *
 
        /* Check if error */
        if (selrtn == -1) {
-               if (errno == EINTR)
-                       return NT_STATUS_RETRY;
-               else
-                       /* Maybe the socket is dead? */
-                       return map_nt_error_from_unix(errno);
-       }
-
-       /* Process events until all available fds have been handled.
-        * This allows for fair round-robin handling of all available fds
-        * on each select() wakeup, while still maintaining responsiveness
-        * by re-checking for signal and timed events between the handling
-        * of each ready fd. */
-       do {
-               run_events(smbd_event_context(), &selrtn, &r_fds, &w_fds);
-       } while (selrtn > 0);
+               /* something is wrong. Maybe the socket is dead? */
+               return map_nt_error_from_unix(errno);
+       }
+
+        if ((conn->smb1.echo_handler.trusted_fd != -1)
+           && FD_ISSET(conn->sock, &r_fds)
+           && FD_ISSET(conn->smb1.echo_handler.trusted_fd, &r_fds)) {
+               /*
+                * Prefer to read pending requests from the echo handler. To
+                * quote Jeremy (da70f8ab1): This is a hack of monstrous
+                * proportions...
+                */
+               FD_CLR(conn->sock, &r_fds);
+        }
+
+       if (run_events(smbd_event_context(), selrtn, &r_fds, &w_fds)) {
+               return NT_STATUS_RETRY;
+       }
 
-       /* Processed all fds or timed out */
+       /* Did we timeout ? */
        if (selrtn == 0) {
                return NT_STATUS_RETRY;
        }
index a32459d595044c4babc44963e1c4ae77126dc3df..ac50a5637a2b434301f24f0bbddcf2e6e11312f4 100644 (file)
@@ -1418,7 +1418,7 @@ static bool fork_domain_child(struct winbindd_child *child)
 
        while (1) {
 
-               int ret = 0;
+               int ret;
                fd_set r_fds;
                fd_set w_fds;
                int maxfd;
@@ -1429,7 +1429,7 @@ static bool fork_domain_child(struct winbindd_child *child)
                int iov_count;
                NTSTATUS status;
 
-               if (run_events(winbind_event_context(), &ret, NULL, NULL)) {
+               if (run_events(winbind_event_context(), 0, NULL, NULL)) {
                        TALLOC_FREE(frame);
                        continue;
                }
@@ -1465,7 +1465,7 @@ static bool fork_domain_child(struct winbindd_child *child)
 
                ret = sys_select(maxfd + 1, &r_fds, &w_fds, NULL, tp);
 
-               if (run_events(winbind_event_context(), &ret, &r_fds, &w_fds)) {
+               if (run_events(winbind_event_context(), ret, &r_fds, &w_fds)) {
                        /* We got a signal - continue. */
                        TALLOC_FREE(frame);
                        continue;