Questions about asyncore

Frank Millman frank at chagford.com
Wed Aug 6 01:16:07 EDT 2008


On Aug 5, 6:18 pm, Josiah Carlson <josiah.carl... at gmail.com> wrote:
>
> Giampaolo already offered up some information, but I will offer these
> two little tidbits:
> In your first client, your handle_read doesn't handle the case where
> you have received multiple packets at one time.  That is, imagine that
> in your one .read(8192), you received exactly two messages (the prefix
> length and the pickle itself times two).  The first pass will pick up
> the message and handle the data.  But unless the socket becomes
> readable again, the second message will never be processed.  And even
> if the socket becomes readable immediately in the next select() call,
> the message will be delayed depending on what other sockets are up
> to.  The asynchat module handles that case just fine.
>
> As for push() vs. send(); send() returns the number of bytes sent.  If
> it sends less than the total block of data (which can be the case with
> large blocks of data, small TCP/IP windows over a slow connection, or
> small TCP/IP buffers), you need to be aware of it and attempt to
> resend the remaining.  Again, the asynchat module handles that case
> just fine with it's .push() method; when it returns, you know that the
> data to be transferred will be transferred as long as the connection
> stays alive.  Without .push(), you need to implement that behavior
> yourself (less boilerplate for every subclass = easier maintenance).
>
> (I normally don't hop on this list to comment, so please cc me on any
> replies)
>  - Josiah
>

Valuable insights. Much appreciated.

Frank



More information about the Python-list mailing list