[Twisted-Python] addWriter

Hello Everyone! I have a server that queues messages for clients. The Queue object has a callback from the ConnectionFactory, which deals with output formatting and holds the Protocol object. As soon as a client connects, the ConnectionFactory peeks in the Queue for messages to be sent. And if there are any, it will send and dequeue and peek again until the Queue is exhausted. Once it's exhausted, the ConnectionFactory will be called (using the callback) by the Queue when the next message is enqueued by the Deliver module. So far, this mechanism works well. But one of its flaws is the partial write situation. If output buffer overflow occurred, I would like to continue doing other things and get called back by the Reactor when the socket is writable again. Moreover, I would like to break the direct association between the Queue and the ConnectionFactory. Instead, I would like to tie them through some kind of a notification strategy (like in ACE), where my ConnectionFactory would be notifed by the Reactor when the socket is writable, then the ConnectionFactory could peek, send, dequeue and wait for the next notification. I thought, addWriter/doWrite is what I need to use. When I used them, my ConnectionFactory's doWrite was never called after a client connected. Is addWriter/doWrite approach correct? Or am I going in a totally wrong direction? Please, help, if you can. Thank you, Alex Scherbina

On Tue, Oct 29, 2002 at 07:00:27PM -0500, Scherbina, Alexander (ASCHERBI) wrote: [..snip..]
Why are having problems with partial writes? Your Protocol should simply call self.transport.write(...), which will take care of all the hard work of sending stuff at the appropriate times. The Reactor will automatically wake up the Transport when the socket is ready for writing, and the Transport will automatically write anything that is waiting to be written.
Is addWriter/doWrite approach correct? Or am I going in a totally wrong direction? Please, help, if you can.
It sounds to me like you're going in completely the wrong direction :) Twisted does all of the hard work for you :) The idea is you simply say "write this to this connection please" and Twisted will do everything else... it'll handle partial writes, it'll handle waiting until the socket is writeable. Have you read the "Writing Clients" HOWTO? -Andrew.

On Tue, 29 Oct 2002 19:00:27 -0500, "Scherbina, Alexander (ASCHERBI)" <ASCHERBI@arinc.com> wrote:
Depending on your requirements, you should either be doing what spiv suggested earlier (e.g. "nothing, just call transport.write") or you should be looking into the producer/consumer API, which will allow you to produce streams of data on demand. Last I checked this wasn't terribly well documented, but it's fairly straightforward and the code in twisted.web.static.FileTransfer is a decent example. -- | <`'> | Glyph Lefkowitz: Traveling Sorcerer | | < _/ > | Lead Developer, the Twisted project | | < ___/ > | http://www.twistedmatrix.com |

On Tue, Oct 29, 2002 at 07:00:27PM -0500, Scherbina, Alexander (ASCHERBI) wrote: [..snip..]
Why are having problems with partial writes? Your Protocol should simply call self.transport.write(...), which will take care of all the hard work of sending stuff at the appropriate times. The Reactor will automatically wake up the Transport when the socket is ready for writing, and the Transport will automatically write anything that is waiting to be written.
Is addWriter/doWrite approach correct? Or am I going in a totally wrong direction? Please, help, if you can.
It sounds to me like you're going in completely the wrong direction :) Twisted does all of the hard work for you :) The idea is you simply say "write this to this connection please" and Twisted will do everything else... it'll handle partial writes, it'll handle waiting until the socket is writeable. Have you read the "Writing Clients" HOWTO? -Andrew.

On Tue, 29 Oct 2002 19:00:27 -0500, "Scherbina, Alexander (ASCHERBI)" <ASCHERBI@arinc.com> wrote:
Depending on your requirements, you should either be doing what spiv suggested earlier (e.g. "nothing, just call transport.write") or you should be looking into the producer/consumer API, which will allow you to produce streams of data on demand. Last I checked this wasn't terribly well documented, but it's fairly straightforward and the code in twisted.web.static.FileTransfer is a decent example. -- | <`'> | Glyph Lefkowitz: Traveling Sorcerer | | < _/ > | Lead Developer, the Twisted project | | < ___/ > | http://www.twistedmatrix.com |
participants (3)
-
Andrew Bennetts
-
Glyph Lefkowitz
-
Scherbina, Alexander (ASCHERBI)