[Twisted-Python] How to make a custom transport based on sendmsg/recvmsg?

Philippe Frycia phil-twisted at tuxeo.org
Fri Feb 22 14:54:30 EST 2008


I would like to make a custom protocol, based on Unix sockets, that is
able to send and receive file descriptors in addition to regular
"stream" data.
At the low level, I can do this with a patched version of eunuchs, that
adds sendmsg() and recvmsg() functionality to python.

I have tried to find my way in the Twisted API documentation and in the
sources, and as far as I found out, I have to override the doWrite()
method of the abstract.FileDescriptor class, and the doRead() method of
one of its subclasses.

The only way I have found until now is to do this in the Protocol
subclass like this:

class TLVProtocol(Protocol):
    def doWrite(self):
        if len(self.tlvstosend)==0:
            return 0
        sendmsg(self.transport.socket.fileno(), data, ancillary=ancillary)

    def doRead(self):
        (data, dummy, dummy, ancillary) =
        if len(data)==0:
            return 0
        tlv=encode(data, ancillary)
        .... # process tlv object

    def connectionMade(self):

    def sendtlv(self, tlv):

Some of the return values are not completed yet (EOF, ...).
Am I completely on the wrong track here ?
If not, what other methods of self.transport do I need to override ?
If yes, what is the correct way to do this ?


More information about the Twisted-Python mailing list