Author: vlendec
Date: 2007-05-15 13:44:11 +0000 (Tue, 15 May 2007)
New Revision: 22902

WebSVN: 
http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=22902

Log:
Add an event_context and a messaging_context to nmbd. Not used yet.

Modified:
   branches/SAMBA_3_0/source/nmbd/nmbd.c
   branches/SAMBA_3_0/source/nmbd/nmbd_packets.c
   branches/SAMBA_3_0_26/source/nmbd/nmbd.c
   branches/SAMBA_3_0_26/source/nmbd/nmbd_packets.c


Changeset:
Modified: branches/SAMBA_3_0/source/nmbd/nmbd.c
===================================================================
--- branches/SAMBA_3_0/source/nmbd/nmbd.c       2007-05-15 13:42:53 UTC (rev 
22901)
+++ branches/SAMBA_3_0/source/nmbd/nmbd.c       2007-05-15 13:44:11 UTC (rev 
22902)
@@ -40,6 +40,27 @@
 
 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 @@
                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 @@
        }
 
        pidfile_create("nmbd");
-       message_init();
        message_register(MSG_FORCE_ELECTION, nmbd_message_election, NULL);
 #if 0
        /* Until winsrepl is done. */

Modified: branches/SAMBA_3_0/source/nmbd/nmbd_packets.c
===================================================================
--- branches/SAMBA_3_0/source/nmbd/nmbd_packets.c       2007-05-15 13:42:53 UTC 
(rev 22901)
+++ branches/SAMBA_3_0/source/nmbd/nmbd_packets.c       2007-05-15 13:44:11 UTC 
(rev 22902)
@@ -1730,7 +1730,8 @@
        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 @@
                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 @@
        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 @@
                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 @@
        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 @@
                        }
                } 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) {
                                        /*

Modified: branches/SAMBA_3_0_26/source/nmbd/nmbd.c
===================================================================
--- branches/SAMBA_3_0_26/source/nmbd/nmbd.c    2007-05-15 13:42:53 UTC (rev 
22901)
+++ branches/SAMBA_3_0_26/source/nmbd/nmbd.c    2007-05-15 13:44:11 UTC (rev 
22902)
@@ -49,6 +49,27 @@
 
 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.
  **************************************************************************** 
*/
@@ -731,6 +752,11 @@
                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 */
@@ -744,7 +770,6 @@
        }
 
        pidfile_create("nmbd");
-       message_init();
        message_register(MSG_FORCE_ELECTION, nmbd_message_election, NULL);
 #if 0
        /* Until winsrepl is done. */

Modified: branches/SAMBA_3_0_26/source/nmbd/nmbd_packets.c
===================================================================
--- branches/SAMBA_3_0_26/source/nmbd/nmbd_packets.c    2007-05-15 13:42:53 UTC 
(rev 22901)
+++ branches/SAMBA_3_0_26/source/nmbd/nmbd_packets.c    2007-05-15 13:44:11 UTC 
(rev 22902)
@@ -1730,7 +1730,8 @@
        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 @@
                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 @@
        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 @@
                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 @@
        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 @@
                        }
                } 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) {
                                        /*

Reply via email to