You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Bill Stoddard <st...@raleigh.ibm.com> on 1999/06/16 23:11:32 UTC

[PATCH] Sharing Win32 sockets between parent and child processes

I'm interested in comments on the patch available here:

http://www.apache.org/~stoddard/share.patch

Summary:
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
win95/98?)

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.

Thanks,
Bill Stoddard

Re: [PATCH] Sharing Win32 sockets between parent and child processes

Posted by Brad Fitzpatrick <br...@bradfitz.com>.
> 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
> win95/98?)

I manage a bunch of Apache installations on FreeBSD machines, but I also
have a few non-critical and experimental installation on Win9x.  Whatever
you change to allow graceful restarts, it'd still be nice to be able to
build Apache for Win9x, as I know a lot of people that run Apache on  
their local machines for testing CGI scripts and other reasons.  I suppose
I just don't want to see NT become a requirement for Apache on Win32, as I
like the convenience of being able to quickly install a copy of Apache
wherever I go, if just for playing around or testing.

Even keeping an old not-maintained Win9x binary on apache.org would be
sufficient for a lot of people.

- Brad