httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bill Stoddard <>
Subject [PATCH] Sharing Win32 sockets between parent and child processes
Date Wed, 16 Jun 1999 21:11:32 GMT
I'm interested in comments on the patch available here:

This patch allows graceful restarts (apache -k restart) that are honored
immediately and which do not loose connections in the TCP stack's listen
queue. It will NOT work on Win95/98 in it's current form (relies on
NamedPipes which are only available on NT). This patch requires Winsock2
(anyone see any serious problems with this? specifically, supporting

The parent process now issues setup_listeners(), which opens, binds and
performs a listen on the sockets. The listening sockets are duplicated
via calls to WSADuplicateSocket(). WSADuplicateSocket returns a
WSAPROTOCL_INFO structure which must be passed to the child process for
use in a subsequent call to WSASocket(). WSASocket returns the socket in
the child process which is then used on the select and accept.

Global changes:
1. Use winsock2
    Link to ws2_32.lib instead of wsock32.lib. Include winsock2.h
instead of winsock.h. Needed to define WIN32_LEAN_AND_MEAN to keep
windows.h from including winsock.h (and producing conflicting
definitions) in os/win32/service.c, registry.c and util_win32.c.

Parent process changes:
1. rewrote create_process()
    replaced spawn... with CreateProcess(), create named pipe,
duplicated open sockets, write resulting WSAPROTOCOL_INFO data to the
pipe to be consued by the child.

2. rewrote much of master_main()
    cleanup, cleanup, cleanup

Child process changes
1. created new function, setup_inherited_listeners, modeled after
setup_listeners, which replaces the make_sock call with function to open
the pipe to the
parent, read the WSAPROTOCOL_INFO info and call WSASocket to generate
the socket used by the child process.

The patch should apply cleanly to 1.3.7-dev extracted today.

In Apache 2.0, I hope to generalize this function to be the accepted way
to share sockets on systems that do not support fork (Win32, AS/400, ?).

APR will hide the OS specific details (pipes, actual calls required to
duplicate the sockets, etc.). It also opens the possibility of running
multiple child processes concurrently.

Please let me know what you think.

Bill Stoddard

View raw message