Overriding 'select'

Thomas Wouters thomas at xs4all.net
Sun Jun 18 07:49:28 EDT 2000


On Sat, Jun 17, 2000 at 10:37:34PM -0500, David Allen wrote:

> The problem is this.  I've got a Connection object.  Each instance
> of a Connection object has a field that is a socket.  The server
> that uses these Connection objects wants to call select() on 
> Connection objects, not their corresponding sockets.  This is
> because the Connection object providesa bunch of methods 
> specific to each connection, and holds a lot of data for the
> server.  

What you want to do is adding a 'fileno()' method to the Connection object.
select.select() does not care about what kind of objects it gets passed, as
long as they have a fileno() method that returns the proper filedescriptor
for that object.

So, add this to your Connection object:

    def fileno(self):
        return self.socket.fileno()

and all should be well. The select.select() returns the objects passed in,
not their filedescriptor, so you do not need to do your own bookkeeping.

> Any ideas on speeding this up, or rewriting in a better
> way?  Is there any way to get around the read-only problem
> on sockets?

Yes, create a wrapper object. But then, you already had that ;)

-- 
Thomas Wouters <thomas at xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!




More information about the Python-list mailing list