r22902: Add an event_context and a messaging_context to nmbd. Not used yet.
authorVolker Lendecke <vlendec@samba.org>
Tue, 15 May 2007 13:44:11 +0000 (13:44 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:22:06 +0000 (12:22 -0500)
source/nmbd/nmbd.c
source/nmbd/nmbd_packets.c

index 6e0de362b983517eb4b2632abcc04806140f2ac9..f328673a5593dfd30b20657310279fcea84a1214 100644 (file)
@@ -40,6 +40,27 @@ BOOL found_lm_clients = False;
 
 time_t StartupTime = 0;
 
+struct event_context *nmbd_event_context(void)
+{
+       static struct event_context *ctx;
+
+       if (!ctx && !(ctx = event_context_init(NULL))) {
+               smb_panic("Could not init nmbd event context\n");
+       }
+       return ctx;
+}
+
+struct messaging_context *nmbd_messaging_context(void)
+{
+       static struct messaging_context *ctx;
+
+       if (!ctx && !(ctx = messaging_init(NULL, server_id_self(),
+                                          nmbd_event_context()))) {
+               smb_panic("Could not init nmbd messaging context\n");
+       }
+       return ctx;
+}
+
 /**************************************************************************** **
  Handle a SIGTERM in band.
  **************************************************************************** */
@@ -732,6 +753,11 @@ static BOOL open_sockets(enum smb_server_mode server_mode, int port)
                setpgid( (pid_t)0, (pid_t)0 );
 #endif
 
+       message_init();
+       if (nmbd_messaging_context() == NULL) {
+               return 1;
+       }
+
 #ifndef SYNC_DNS
        /* Setup the async dns. We do it here so it doesn't have all the other
                stuff initialised and thus chewing memory and sockets */
@@ -745,7 +771,6 @@ static BOOL open_sockets(enum smb_server_mode server_mode, int port)
        }
 
        pidfile_create("nmbd");
-       message_init();
        message_register(MSG_FORCE_ELECTION, nmbd_message_election, NULL);
 #if 0
        /* Until winsrepl is done. */
index d34beb7ff611d9a23816437229b623531a51ef9a..2fbf2f41468356a93ab43f6ba6db28a24a2da788 100644 (file)
@@ -1730,7 +1730,8 @@ BOOL listen_for_packets(BOOL run_election)
        int i;
        static int maxfd = 0;
 
-       fd_set fds;
+       fd_set r_fds;
+       fd_set w_fds;
        int selrtn;
        struct timeval timeout;
 #ifndef SYNC_DNS
@@ -1745,12 +1746,13 @@ BOOL listen_for_packets(BOOL run_election)
                rescan_listen_set = False;
        }
 
-       memcpy((char *)&fds, (char *)listen_set, sizeof(fd_set));
+       memcpy((char *)&r_fds, (char *)listen_set, sizeof(fd_set));
+       FD_ZERO(&w_fds);
 
 #ifndef SYNC_DNS
        dns_fd = asyncdns_fd();
        if (dns_fd != -1) {
-               FD_SET(dns_fd, &fds);
+               FD_SET(dns_fd, &r_fds);
                maxfd = MAX( maxfd, dns_fd);
        }
 #endif
@@ -1765,11 +1767,24 @@ BOOL listen_for_packets(BOOL run_election)
        timeout.tv_sec = (run_election||num_response_packets) ? 1 : NMBD_SELECT_LOOP;
        timeout.tv_usec = 0;
 
+       {
+               struct timeval now = timeval_current();
+               event_add_to_select_args(nmbd_event_context(), &now,
+                                        &r_fds, &w_fds, &timeout, &maxfd);
+       }
+
+       if (timeval_is_zero(&timeout)) {
+               /* Process a timed event now... */
+               if (run_events(nmbd_event_context(), 0, NULL, NULL)) {
+                       return False;
+               }
+       }
+       
        /* Prepare for the select - allow certain signals. */
 
        BlockSignals(False, SIGTERM);
 
-       selrtn = sys_select(maxfd+1,&fds,NULL,NULL,&timeout);
+       selrtn = sys_select(maxfd+1,&r_fds,&w_fds,NULL,&timeout);
 
        /* We can only take signals when we are in the select - block them again here. */
 
@@ -1779,8 +1794,12 @@ BOOL listen_for_packets(BOOL run_election)
                return False;
        }
 
+       if (run_events(nmbd_event_context(), selrtn, &r_fds, &w_fds)) {
+               return False;
+       }
+
 #ifndef SYNC_DNS
-       if (dns_fd != -1 && FD_ISSET(dns_fd,&fds)) {
+       if (dns_fd != -1 && FD_ISSET(dns_fd,&r_fds)) {
                run_dns_queue();
        }
 #endif
@@ -1788,7 +1807,7 @@ BOOL listen_for_packets(BOOL run_election)
        for(i = 0; i < listen_number; i++) {
                if (i < (listen_number/2)) {
                        /* Processing a 137 socket. */
-                       if (FD_ISSET(sock_array[i],&fds)) {
+                       if (FD_ISSET(sock_array[i],&r_fds)) {
                                struct packet_struct *packet = read_packet(sock_array[i], NMB_PACKET);
                                if (packet) {
                                        /*
@@ -1815,7 +1834,7 @@ BOOL listen_for_packets(BOOL run_election)
                        }
                } else {
                        /* Processing a 138 socket. */
-                               if (FD_ISSET(sock_array[i],&fds)) {
+                               if (FD_ISSET(sock_array[i],&r_fds)) {
                                struct packet_struct *packet = read_packet(sock_array[i], DGRAM_PACKET);
                                if (packet) {
                                        /*