]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3: nmbd: Change over to using tevent functions from direct poll.
authorJeremy Allison <jra@samba.org>
Fri, 23 Sep 2016 19:31:00 +0000 (12:31 -0700)
committerKarolin Seeger <kseeger@samba.org>
Thu, 20 Oct 2016 08:43:28 +0000 (10:43 +0200)
This will allow us to eventually remove source3/lib/events.c
dependency and make nmbd purely tevent based.

Bug: https://bugzilla.samba.org/show_bug.cgi?id=12283
Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
(cherry picked from commit b857bf9b3fa3a836647edc40ead92db7b782d367)

source3/nmbd/nmbd_packets.c

index 8d40eaf568cb6a67f413824136c26aa51fd5a64c..10a0c0ae1453f0976c52756c5bf6abdf8e6e73ed 100644 (file)
@@ -1909,14 +1909,16 @@ bool listen_for_packets(struct messaging_context *msg, bool run_election)
        static int listen_number = 0;
        int num_sockets;
        int i;
+       int loop_rtn;
+       int timeout_secs;
 
-       int pollrtn;
-       int timeout;
 #ifndef SYNC_DNS
        int dns_fd;
        int dns_pollidx = -1;
 #endif
        struct processed_packet *processed_packet_list = NULL;
+       struct tevent_timer *te = NULL;
+       bool got_timeout = false;
        TALLOC_CTX *frame = talloc_stackframe();
 
        if ((fds == NULL) || rescan_listen_set) {
@@ -1972,13 +1974,17 @@ bool listen_for_packets(struct messaging_context *msg, bool run_election)
 #endif
 
        for (i=0; i<num_sockets; i++) {
-               fds[i].events = POLLIN|POLLHUP;
-       }
-
-       /* Process a signal and timer events now... */
-       if (run_events_poll(nmbd_event_context(), 0, NULL, 0)) {
-               TALLOC_FREE(frame);
-               return False;
+               struct tevent_fd *tfd = tevent_add_fd(nmbd_event_context(),
+                                                       frame,
+                                                       attrs[i].fd,
+                                                       TEVENT_FD_READ,
+                                                       nmbd_fd_handler,
+                                                       &attrs[i]);
+               if (tfd == NULL) {
+                       TALLOC_FREE(frame);
+                       return true;
+               }
+               attrs[i].triggered = false;
        }
 
        /*
@@ -1988,28 +1994,40 @@ bool listen_for_packets(struct messaging_context *msg, bool run_election)
         * the time we are expecting the next netbios packet.
         */
 
-       timeout = ((run_election||num_response_packets)
-                  ? 1 : NMBD_SELECT_LOOP) * 1000;
+       if (run_election||num_response_packets) {
+               timeout_secs = 1;
+       } else {
+               timeout_secs = NMBD_SELECT_LOOP;
+       }
 
-       event_add_to_poll_args(nmbd_event_context(), NULL,
-                              &fds, &num_sockets, &timeout);
+       te = tevent_add_timer(nmbd_event_context(),
+                               frame,
+                               tevent_timeval_current_ofs(timeout_secs, 0),
+                               nmbd_timeout_handler,
+                               &got_timeout);
+       if (te == NULL) {
+               TALLOC_FREE(frame);
+               return true;
+       }
 
-       pollrtn = poll(fds, num_sockets, timeout);
+       loop_rtn = tevent_loop_once(nmbd_event_context());
 
-       if (run_events_poll(nmbd_event_context(), pollrtn, fds, num_sockets)) {
+       if (loop_rtn == -1) {
                TALLOC_FREE(frame);
-               return False;
+               return true;
        }
 
-       if (pollrtn == -1) {
+       if (got_timeout) {
                TALLOC_FREE(frame);
-               return False;
+               return false;
        }
 
 #ifndef SYNC_DNS
        if ((dns_fd != -1) && (dns_pollidx != -1) &&
-           (fds[dns_pollidx].revents & (POLLIN|POLLHUP|POLLERR))) {
+           attrs[dns_pollidx].triggered){
                run_dns_queue(msg);
+               TALLOC_FREE(frame);
+               return false;
        }
 #endif
 
@@ -2020,7 +2038,7 @@ bool listen_for_packets(struct messaging_context *msg, bool run_election)
                int client_fd;
                int client_port;
 
-               if ((fds[i].revents & (POLLIN|POLLHUP|POLLERR)) == 0) {
+               if (!attrs[i].triggered) {
                        continue;
                }