M2Crypto: select() behaves weird on SSL sockets

Steve Holden sholden at holdenweb.com
Fri Jun 28 08:56:10 EDT 2002


"Irmen de Jong" <irmen at NOSPAMREMOVETHISxs4all.nl> wrote in message
news:3D1B92A2.7030605 at NOSPAMREMOVETHISxs4all.nl...
> Kragen Sitaker wrote:
>
> > There are many pieces of middle ground between complete threading (two
> > threads per connection) and complete event-loop-drivenness with just
> > one thread --- as you're obviously aware, since you're using select()
> > in a threaded program.
>
> Um, yeah. I have 1 loop using select() that waits for new incoming
> connections. Every thread that is started for a connection just
> recv()s data off the socket.
>
> > What I guess you're not aware of is that asyncore supports the middle
> > ground (middle colors?) as well as the event-loop-driven end of the
> > spectrum.  For example, Zope has an asyncore thread that handles I/O,
> > but actually processes requests and produces results in some child
> > threads.
>
> You're probably right. I don't know a lot about the workings of asyncore.
> Perhaps if I finally squash the bug that is still in Pyro 3
> -- *blushes* it's probably a threading race condition -- I'll spend
> some time looking at it.
>
I understand that Zope used the asyncore code as a basis for development
rather than adopting it outright, but I haven't actually checked the source
to ensure this is so.

> Doing stuff the Zope way, the worker threads must have some way to
> get to the input and output streams that are handled in asyncore, right?
>
Well, it's a relatively simple matter: when an asyncore channel's
handle-connect() method is called, one fo the arguments is the socket that
was created by the connection. handle_connect() simply uses this socket to
create another channel, which is added to the map used by the asynchronous
select() loop.

This new channel then starts to fire handle_read() method calls, which you
service by doing something with the data. If the something you do includes
putting data in an output buffer then handle_write() events also start to
occur.

asyncore/asynchat really repay the effort of study, so I would advise you to
take a fresh look when you get time.

To assist you, I plan to add documentation for asynchat for 2.3.

when-sourceforge-stops-playing-silly-buggers-ly y'rs  - steve
-----------------------------------------------------------------------
Steve Holden                                 http://www.holdenweb.com/
Python Web Programming                http://pydish.holdenweb.com/pwp/
-----------------------------------------------------------------------








More information about the Python-list mailing list