r15700: Make nmbd udp sockets non-blocking to prevent problem
authorJeremy Allison <jra@samba.org>
Thu, 18 May 2006 19:49:44 +0000 (19:49 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 16:17:08 +0000 (11:17 -0500)
with select returning true but no data being available.
Fix for bug #3779.
Jeremy.
(This used to be commit e5787cf75b2e7d50f551f34f28d280c27b0aa134)

source3/lib/util_sock.c
source3/nmbd/nmbd.c
source3/nmbd/nmbd_responserecordsdb.c
source3/nmbd/nmbd_serverlistdb.c
source3/nmbd/nmbd_subnetdb.c
source3/nmbd/nmbd_workgroupdb.c

index de90b29294e7c272f928eeeb77dfe7fc4cad9b3a..1a73a310b62de2e528a96e95354d7c1a3f54b41f 100644 (file)
@@ -278,7 +278,12 @@ ssize_t read_udp_socket(int fd,char *buf,size_t len)
        memset((char *)&lastip,'\0',sizeof(lastip));
        ret = (ssize_t)sys_recvfrom(fd,buf,len,0,(struct sockaddr *)&sock,&socklen);
        if (ret <= 0) {
-               DEBUG(2,("read socket failed. ERRNO=%s\n",strerror(errno)));
+               /* Don't print a low debug error for a non-blocking socket. */
+               if (errno == EAGAIN) {
+                       DEBUG(10,("read socket returned EAGAIN. ERRNO=%s\n",strerror(errno)));
+               } else {
+                       DEBUG(2,("read socket failed. ERRNO=%s\n",strerror(errno)));
+               }
                return(0);
        }
 
index fca17d1ff7b5cf17d309d7dc793bfec5e6c24bcf..9c8f99df252196e9ee6fd66173b705f4490c4f31 100644 (file)
@@ -605,6 +605,10 @@ static BOOL open_sockets(BOOL isdaemon, int port)
        set_socket_options( ClientNMB,   "SO_BROADCAST" );
        set_socket_options( ClientDGRAM, "SO_BROADCAST" );
 
+       /* Ensure we're non-blocking. */
+       set_blocking( ClientNMB, False);
+       set_blocking( ClientDGRAM, False);
+
        DEBUG( 3, ( "open_sockets: Broadcast sockets opened.\n" ) );
        return( True );
 }
index a5903ef462ed9decd3b833b46f9503a5c3f50c62..6f22fd906deaa09ee58eaa0bae08dfbc7fa4d885 100644 (file)
@@ -23,8 +23,6 @@
 
 #include "includes.h"
 
-extern int ClientNMB;
-
 int num_response_packets = 0;
 
 /***************************************************************************
index 52d00e15854afe337b1c6c19f26e7b46decfc524..cc762ae8d23a4706363d8fdb57bf1b96c5ef6c2e 100644 (file)
@@ -23,8 +23,6 @@
 
 #include "includes.h"
 
-extern int ClientNMB;
-
 int updatecount = 0;
 
 /*******************************************************************
index b2e1178bebcdcaaf019638d567eef7a3ecc378d9..c3640028d27a30b45483ea6b9a62fc7a87516932 100644 (file)
@@ -26,8 +26,6 @@
 #include "includes.h"
 
 extern struct in_addr loopback_ip;
-extern int ClientNMB;
-extern int ClientDGRAM;
 extern int global_nmb_port;
 
 /* This is the broadcast subnets database. */
@@ -118,6 +116,10 @@ static struct subnet_record *make_subnet(const char *name, enum subnet_type type
                /* Make sure we can broadcast from these sockets. */
                set_socket_options(nmb_sock,"SO_BROADCAST");
                set_socket_options(dgram_sock,"SO_BROADCAST");
+
+               /* Set them non-blocking. */
+               set_blocking(nmb_sock, False);
+               set_blocking(dgram_sock, False);
        }
 
        subrec = SMB_MALLOC_P(struct subnet_record);
index 335d5220310fc4d6cae6006c1d9ca2db260e1fb5..ca665bdf4f5ef5366a99dd22b584061293f6ecc7 100644 (file)
@@ -23,8 +23,6 @@
 
 #include "includes.h"
 
-extern int ClientNMB;
-
 extern uint16 samba_nb_type;
 
 int workgroup_count = 0; /* unique index key: one for each workgroup */