asyncore: suggested patch

Panu A Kalliokoski pkalliok at cc.helsinki.fi
Thu May 31 12:57:29 CEST 2001


Panu A Kalliokoski <pkalliok at cc.helsinki.fi> wrote:
> It all depends on how the socket initialisation sequence is done. When the 
> dispatcher arrives in connect(), it should already be non-blocking. Then 
> the code should work. But a smarter way would be to use blocking sockets.

On a related note, connect() (and open()) is one of those system calls
that cannot be select()ed upon _before_ they block. (Hooray! Praise Un*x!)
Thus, you have to make the socket non-blocking, connect(), catch the error
(which it always produces), make the socket blocking and _then_ enter
select() with that socket as well as other possible connecting /
established ones.

Because it's your connect, you probably want to know when the fd is ready
for writing. (If the protocol specifies server-initiated handshakes, this
is of course unnecessary.) In the selecting package, you do this by
putting your data into the send buffer of your connecting socket. The data
will get sent when the connection has been established, probably producing
a response, which you then will be notified of by calling your channel
handler's receive(), as usual.

Maybe I should add code for this into selecting's TCPServer.py. Usually
it's the case that select()ing programs only accept connections, so I
never thought thoroughly about this issue of sync mux connect()s.

Panu Kalliokoski



More information about the Python-list mailing list