From 0caeda53d37740d18b38e6d37d0ecef8c6336820 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 29 Oct 2004 07:00:14 +0000 Subject: 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) --- source4/lib/socket/socket.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'source4/lib/socket') 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 || -- cgit