[Python-Dev] socket module recvmsg/sendmsg

Heiko Wundram me+python-dev at modelnine.org
Sun Apr 30 21:33:15 CEST 2006


Hi all!

I've implemented recvmsg and sendmsg for the socket module in my private 
Python tree for communication between two forked processes, which are 
essentially wrappers for proper handling of SCM_RIGHTS and SCM_CREDENTIALS 
Unix-Domain-Socket messages (which are the two types of messages that are 
defined on Linux).

The main reason I need these two primitives is that I require (more or less 
transparent) file/socket descriptor exchange between two forked processes, 
where one process accepts a socket, and delegates processing of the socket 
connection to another process of a set of processes; this is much like a 
ForkingTCPServer, but with the Handler-process prestarted.

As connection to the Unix-Domain-Socket is openly available, the receiving 
process needs to check the identity of the first process; this is done using 
a getsockopt(SO_PEERCRED) call, which is also handled more specifically by my 
socket extension to return a socket._ucred-type structure, which wraps the 
pid/uid/gid-structure returned by the corresponding getsockopt call, and also 
the socket message (SCM_CREDENTIALS) which passes or sets this information 
for the remote process.

I'd love to see these two socket message primitives (of which the first, 
SCM_RIGHTS, is available on pretty much any Unix derivative) included in a 
Python distribution at some point in time, and as I've not got the time to 
push for an inclusion in the tree (and even less time to work on other Python 
patches myself) at the moment, I thought that I might just post here so that 
someone interested might pick up the work I've done so far and check the 
implementation for bugs, and at some stage these two functions might actually 
find their way into the Python core.

Anyway, my private Python tree (which has some other patches which aren't of 
general interest, I'd think) is available at:

http://dev.modelnine.org/hg/python

and I can, if anyone is interested, post a current diff of socketmodule.* 
against 2.4.3 to the Python bug tracker at sourceforge. I did that some time 
ago (about half a year) when socket-passing code wasn't completely 
functioning yet, but at least at that point there didn't seem much interest 
in the patch. The patch should apply pretty cleanly against the current HEAD 
too, at least it did the last time I checked.

I'll add a small testsuite for both functions to my tree some time tomorrow.

--- Heiko.


More information about the Python-Dev mailing list