Unix Domain Sockets in Webware

New version: unix-sockets-patch-2001-03-13T2245Z.gz

To force myself to get my feet wet in Webware, I created a patch to add support for unix domain sockets. unix-sockets-patch-2001-03-13T1135Z.gz I did it because I wanted to try a "minor" enhancement. It ended up being a lot more work than I ancipated, but I learned a lot.

I have tested it lightly with WebKit.cgi, and it works for me. Subjectively, it seems a little faster, but I have not done real time comparisons with INET sockets.

Known bugs

It doesn't work on Windows or Mac (pre MacOS X). (This is a platform bug. :-) ) I know that NT supports named pipes, but I don't know how to use them from Python, and I don't have a Windows box to test it on.

My tabs may not be exactly right.

I did not change any C code in mod_webkit. (I would expect to see more improvement here than in WebKit.cgi)

Does FastCGI support unix sockets at all?

patch is bad

Monitor.py is using the wrong filename for the client socket.

AppServer.config changes

Replaces 'Host' and 'Port' ('Host' and 'Port' still work if you want to use AF_INET sockets).
"Host": "localhost",
"Port": 8086,
"SocketAddress": ("localhost",8086),
The Unix socket name is passed through serverSidePath()
An integer indicating the required permissions for the socket file. e.g. If your cgi scripts run as apache or nobody, the socket needs to be world writable.
"SocketPermissions": 0666,
If you do not include this setting, the socket will have the default permissions (i.e. AppServer will make no chmod call.)
Port to be used by the Monitor. This may be an integer TCP port number or a string socket filename. If not supplied, the default is setting("Port")-1 for AF_INET or setting("SocketAddress")+".monitor" for AF_UNIX.
"Host": "localhost",
"Port": 8086,
"MonitorPort": 8085,
"SocketAddress": "var/AppServer.sock",
"MonitorPort": "var/AppServer.sock.monitor",

Note that it is possible to use AF_INET for the AppServer and AF_UNIX for the monitor (or vice versa), but the default is to use the same address family.

SocketPermissions is not applied to the monitor port. Convince me that it is necessary and I will add it.

The Unix socket name is passed through serverSidePath()

AppServer Changes

I added a list attribute to remove the socket files in AppServer.shutDown. (If you leave them around, you cannot bind to them again.) I also added "address.text" to this list, so it now gets deleted too.

Changes to ThreadedAppserver and AsyncThreadedAppServer

These are ripe for refactoring: they have a lot of duplicate code. Should it be pushed down into AppServer?

Wherever I saw AF_INET, I added a parallel case for AF_UNIX.
Changed the configuration code to support the settings described above.

*Adapter, Monitor Changes

common parsing

I changed transactWithAppServer to require a single argument "address" in place of the previous "host","port" pair. I fixed all callers of this method. Then I added a method connectToAppServer(self,address) that parses the address, creates an appropriate socket, and connects to it. This allowed me to eliminate the "host:port" parsing that was done in three different ways in five different places.

The unix socket name is joined with WebKitDir.

client sockets
Wherever I saw AF_INET, I added a parallel case for AF_UNIX.