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

Philippe Frycia phil-twisted at tuxeo.org
Fri Feb 22 15:10:35 MST 2008


Drew Smathers wrote:
> You should not make assumptions about the transport layer in your
> protocol implementation - be it Unix domain sockets, TCP, etc.
>   
In my case, it is not only an assumption: the applications I want to 
interact with do use unix sockets and file descriptor passing.
Maybe my assumption that I need to use a Protocol is wrong, if I need a 
specific transport.

> If you don't see an attribute documented in the interface for
> something (ITransport here for example), and you're referencing it on
> the implementation, then you're most definitely doing something bad.
> The attribute I'm talking about here is "socket."
>   
OK. So what attribute(s) do I have to replace/override to plug my 
low-level read/write routines in a protocol ?

> It sounds like you're trying to do something relatively low-level
> (interfacing with eunuchs directly) at a high-level using Protocols.
>   
Maybe I don't need to use a Protocol at all. But what else ?
> So to do something that isn't just a hack, you'll need to do a lot
> more work - and it might not be worth the effort.  Can you describe
> first why you need to use sendmsg/recvmsg in your application?
>   

As I said above, I would like to interact with a set of (existing) 
applications that use unix sockets and TLV-based messages for 
interprocess communication.
They also use file descriptor passing with sendmsg/recvmsg.
In fact, this is the way they find each other: services announce 
themselves to a central broker, and clients ask for services to this 
broker. The broker then creates a socketpair and passes the file 
descriptor of both ends to each party.
They also make use of this file descriptor passing mechanism to use 
specific devices from different processes while keeping their state and 
"ownership": once one process has made some initialization on a device, 
it can pass the descriptor to another process that can use it further.

The C framework on which these applications are written is completely 
asynchronous and the model seems fine.
I was able to use asyncore with eunuchs to do this low-level stuff as 
prototype, but I really would like to use Twisted instead.

As far as I can see, the low-level doRead and doWrite implementations 
are about the only thing I have to plug in the system to have it working.
In fact my sample code is mostly working, I just want to be sure I do it 
The Right Way, if at all possible.

Please, don't tell me Twisted is not made for something other than byte 
stream based comms... :-)

Thank you for your help.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20080222/db13b90e/attachment.html>


More information about the Twisted-Python mailing list