summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2004-11-19 19:32:31 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 10:53:23 -0500
commita68172ce7cc6c3c9cb02c1b07add9ad1c9c50bbe (patch)
treee511ff86b065116ad32d12ba7a4fd14692dba6fa
parent7c93bdcdf8334d4f2140405a982ea02943c5553c (diff)
downloadsamba-a68172ce7cc6c3c9cb02c1b07add9ad1c9c50bbe.tar.gz
samba-a68172ce7cc6c3c9cb02c1b07add9ad1c9c50bbe.tar.bz2
samba-a68172ce7cc6c3c9cb02c1b07add9ad1c9c50bbe.zip
r3877: Final (I hope :-) fix for #2050 from Lars Müller for select maxfd's.
Jeremy. (This used to be commit 65fc39fc388244923d1e36076b5a4116aa434be5)
-rw-r--r--source3/nmbd/nmbd_packets.c22
-rw-r--r--source3/smbd/server.c9
-rw-r--r--source3/wrepld/server.c10
3 files changed, 17 insertions, 24 deletions
diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c
index 9dd2d05e14..a81b28ec74 100644
--- a/source3/nmbd/nmbd_packets.c
+++ b/source3/nmbd/nmbd_packets.c
@@ -1635,16 +1635,6 @@ on subnet %s\n", rrec->response_id, inet_ntoa(rrec->packet->ip), subrec->subnet_
}
/****************************************************************************
- Check and if required set the highest fd.
-***************************************************************************/
-
-void check_set_maxfd( int *maxfd, int fd)
-{
- if ( *maxfd < fd )
- *maxfd = fd;
-}
-
-/****************************************************************************
Create an fd_set containing all the sockets in the subnet structures,
plus the broadcast sockets.
***************************************************************************/
@@ -1682,25 +1672,25 @@ only use %d.\n", (count*2) + 2, FD_SETSIZE));
/* Add in the broadcast socket on 137. */
FD_SET(ClientNMB,pset);
sock_array[num++] = ClientNMB;
- check_set_maxfd( maxfd, ClientNMB);
+ *maxfd = MAX( *maxfd, ClientNMB);
/* Add in the 137 sockets on all the interfaces. */
for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) {
FD_SET(subrec->nmb_sock,pset);
sock_array[num++] = subrec->nmb_sock;
- check_set_maxfd( maxfd, subrec->nmb_sock);
+ *maxfd = MAX( *maxfd, subrec->nmb_sock);
}
/* Add in the broadcast socket on 138. */
FD_SET(ClientDGRAM,pset);
sock_array[num++] = ClientDGRAM;
- check_set_maxfd( maxfd, ClientDGRAM);
+ *maxfd = MAX( *maxfd, ClientDGRAM);
/* Add in the 138 sockets on all the interfaces. */
for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) {
FD_SET(subrec->dgram_sock,pset);
sock_array[num++] = subrec->dgram_sock;
- check_set_maxfd( maxfd, subrec->dgram_sock);
+ *maxfd = MAX( *maxfd, subrec->dgram_sock);
}
*listen_number = (count*2) + 2;
@@ -1725,7 +1715,7 @@ BOOL listen_for_packets(BOOL run_election)
static int listen_number = 0;
static int *sock_array = NULL;
int i;
- int maxfd = 0;
+ static int maxfd = 0;
fd_set fds;
int selrtn;
@@ -1748,7 +1738,7 @@ BOOL listen_for_packets(BOOL run_election)
dns_fd = asyncdns_fd();
if (dns_fd != -1) {
FD_SET(dns_fd, &fds);
- check_set_maxfd( &maxfd, dns_fd);
+ maxfd = MAX( maxfd, dns_fd);
}
#endif
diff --git a/source3/smbd/server.c b/source3/smbd/server.c
index 5f2713bb83..156755a5b8 100644
--- a/source3/smbd/server.c
+++ b/source3/smbd/server.c
@@ -186,7 +186,7 @@ static BOOL open_sockets_smbd(BOOL is_daemon, BOOL interactive, const char *smb_
int fd_listenset[FD_SETSIZE];
fd_set listen_set;
int s;
- int max_fd = 0;
+ int maxfd = 0;
int i;
char *ports;
@@ -249,9 +249,6 @@ static BOOL open_sockets_smbd(BOOL is_daemon, BOOL interactive, const char *smb_
if(s == -1)
return False;
- if (max_fd < s)
- max_fd = s;
-
/* ready to listen */
set_socket_options(s,"SO_KEEPALIVE");
set_socket_options(s,user_socket_options);
@@ -265,6 +262,7 @@ static BOOL open_sockets_smbd(BOOL is_daemon, BOOL interactive, const char *smb_
return False;
}
FD_SET(s,&listen_set);
+ maxfd = MAX( maxfd, s);
num_sockets++;
if (num_sockets >= FD_SETSIZE) {
@@ -307,6 +305,7 @@ static BOOL open_sockets_smbd(BOOL is_daemon, BOOL interactive, const char *smb_
fd_listenset[num_sockets] = s;
FD_SET(s,&listen_set);
+ maxfd = MAX( maxfd, s);
num_sockets++;
@@ -341,7 +340,7 @@ static BOOL open_sockets_smbd(BOOL is_daemon, BOOL interactive, const char *smb_
memcpy((char *)&lfds, (char *)&listen_set,
sizeof(listen_set));
- num = sys_select(max_fd+1,&lfds,NULL,NULL,NULL);
+ num = sys_select(maxfd+1,&lfds,NULL,NULL,NULL);
if (num == -1 && errno == EINTR) {
if (got_sig_term) {
diff --git a/source3/wrepld/server.c b/source3/wrepld/server.c
index d78e0b206f..9d035a6cbf 100644
--- a/source3/wrepld/server.c
+++ b/source3/wrepld/server.c
@@ -164,7 +164,7 @@ void exit_server(const char *reason)
plus the broadcast sockets.
***************************************************************************/
-static BOOL create_listen_fdset(void)
+static BOOL create_listen_fdset( int *maxfd)
{
int i;
int num_interfaces = iface_count();
@@ -221,6 +221,7 @@ static BOOL create_listen_fdset(void)
}
add_fd_to_sock_array(s);
FD_SET(s, listen_set);
+ *maxfd = MAX( *maxfd, s);
}
} else {
/* Just bind to 0.0.0.0 - accept connections from anywhere. */
@@ -243,6 +244,7 @@ static BOOL create_listen_fdset(void)
add_fd_to_sock_array(s);
FD_SET(s, listen_set);
+ *maxfd = MAX( *maxfd, s);
}
return True;
@@ -346,10 +348,11 @@ static BOOL listen_for_wins_packets(void)
int num_interfaces = iface_count();
fd_set fds;
int i, num, s, new_s;
+ static int maxfd = 0;
struct timeval timeout;
if(listen_set == NULL) {
- if(!create_listen_fdset()) {
+ if(!create_listen_fdset( &maxfd)) {
DEBUG(0,("listen_for_packets: Fatal error. unable to create listen set. Exiting.\n"));
return True;
}
@@ -364,7 +367,7 @@ static BOOL listen_for_wins_packets(void)
BlockSignals(False, SIGTERM);
- num = sys_select(FD_SETSIZE, &fds, NULL, NULL, &timeout);
+ num = sys_select(maxfd+1, &fds, NULL, NULL, &timeout);
/* We can only take signals when we are in the select - block them again here. */
@@ -397,6 +400,7 @@ static BOOL listen_for_wins_packets(void)
set_socket_options(new_s, user_socket_options);
FD_SET(new_s, listen_set);
add_fd_to_sock_array(new_s);
+ maxfd = MAX( maxfd, new_s);
}
}