[Twisted-Python] Socket Read Write
I am writing a chat socket server and need to make sure that there are no conflicts when writing to other attached clients. I am concerned that when the server receives lots of messages from many socket connections, several sockets may encounter write contention. Is there a queue for the write method of a socket? Should one expect errors in this regard? Does the Twisted architecture eliminate this class of error? Using twisted.protocol.basic can 2 lineReceived events happen simultaneously? How is this addressed? Thanks, Theodore E. Patrick PowerSDK - Code for a distributed world http://www.powersdk.com
On Mon, Nov 03, 2003 at 07:03:48AM -0500, Ted Patrick wrote:
I am writing a chat socket server and need to make sure that there are no conflicts when writing to other attached clients. I am concerned that when the server receives lots of messages from many socket connections, several sockets may encounter write contention.
Twisted's network code is single-threaded. Only one event is processed at once, so the answers to your questions are:
Is there a queue for the write method of a socket?
No -- there doesn't need to be. The transport will buffer any write that isn't immediately writeable without blocking, but because you never do this from more than one thread at a time, there are no possible races here.
Should one expect errors in this regard?
Nope :)
Does the Twisted architecture eliminate this class of error?
Yep :)
Using twisted.protocol.basic can 2 lineReceived events happen simultaneously? How is this addressed?
They can't happen simultaneously. :) If you are using threads in your Twisted app, be sure to read: http://twistedmatrix.com/documents/howto/threading -Andrew.
participants (2)
-
Andrew Bennetts
-
Ted Patrick