From ab7a9d2bbe95ac2194db7eb358e3bf1ba4aa8890 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 15 May 2007 13:44:11 +0000 Subject: r22902: Add an event_context and a messaging_context to nmbd. Not used yet. (This used to be commit 6d210fb8a13e93fe5b7bc160a343f74878dea727) --- source3/nmbd/nmbd_packets.c | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) (limited to 'source3/nmbd/nmbd_packets.c') diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index d34beb7ff6..2fbf2f4146 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -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) { /* -- cgit