socket.socket() is not directly implemented by Modules/socketmodule.c. So you can't pass a
socket.socket() into C and expect a
PySocketSockObject*. You need to pass
._sock ... that's a
PySocketSockObject*, i.e. the socket implemented in Modules/socketmodule.c.
Messages on unix domain datagram sockets trigger
handle_connect() and then
handle_read(). I just
pass on the connect.
Pyrex doesn't work as advertised. Simple direct embedding, however, works fine... but only if you build the shared python library (at least, that's the only consistent difference between working and non-working that I've noticed so far).
Writing a module in C is very easy.