summaryrefslogtreecommitdiff
path: root/source4/lib
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2004-10-29 07:00:14 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:05:00 -0500
commit0caeda53d37740d18b38e6d37d0ecef8c6336820 (patch)
tree52ca50fa644464ca50f1a6c14b83b8ce19b3d2d5 /source4/lib
parentbc24603e41804a1d54ff85f9114f0288a03483fa (diff)
downloadsamba-0caeda53d37740d18b38e6d37d0ecef8c6336820.tar.gz
samba-0caeda53d37740d18b38e6d37d0ecef8c6336820.tar.bz2
samba-0caeda53d37740d18b38e6d37d0ecef8c6336820.zip
r3356: in the standard process model we need to make sure we close all
listening sockets after the fork to prevent the child still listening on incoming requests. I have also added an optimisation where we use dup()/close() to lower the file descriptor number of the new socket to the lowest possible after closing our listening sockets. This keeps the max fd num passed to select() low, which makes a difference to the speed of select(). (This used to be commit f2a9bbc317ba86ebe87c3ca27a3a0192de91014d)
Diffstat (limited to 'source4/lib')
-rw-r--r--source4/lib/socket/socket.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/source4/lib/socket/socket.c b/source4/lib/socket/socket.c
index dbbae5ea7e..892695f6eb 100644
--- a/source4/lib/socket/socket.c
+++ b/source4/lib/socket/socket.c
@@ -260,6 +260,28 @@ int socket_get_fd(struct socket_context *sock)
return sock->ops->get_fd(sock);
}
+/*
+ call dup() on a socket, and close the old fd. This is used to change
+ the fd to the lowest available number, to make select() more
+ efficient (select speed depends on the maxiumum fd number passed to
+ it)
+*/
+NTSTATUS socket_dup(struct socket_context *sock)
+{
+ int fd;
+ if (sock->fd == -1) {
+ return NT_STATUS_INVALID_HANDLE;
+ }
+ fd = dup(sock->fd);
+ if (fd == -1) {
+ return map_nt_error_from_unix(errno);
+ }
+ close(sock->fd);
+ sock->fd = fd;
+ return NT_STATUS_OK;
+
+}
+
const struct socket_ops *socket_getops_byname(const char *name, enum socket_type type)
{
if (strcmp("ip", name) == 0 ||