Re: select

Lance Ellinghouse (lance@markv.com)
Sun, 28 Jun 92 14:55:33 PDT

> | Has anyone created a select function similar to the select in BSD sockets?
> |
> | I figured you could pass a list of items in and have it return
> | a 3 element tupple of the return values..
>
> Not yet, but I was thinking more in the direction of the poll() SYSV
> system call. It provides nicer semantics than the bitmask directed
> select().
>
> It would look like:
>
> file1 = open ('...', 'r')
> file2 = open ('...', 'r')
> timeout = 0
>
> filelist = select (((file1, 'r'), (file2, 'r')), timeout)
>
> The input would be a list of (fileobject, string) pairs. The string
> would indicate 'r', 'w', 'e', or any permutation of those letters (for
> read, write and exception; if you really want to confuse people you
> could change the 'e' into an 'x' :-) :-).

'e' sounds reasonable as does the layout of the call.
The question is how do you specify you wish to select/poll on it
for both reading and writing? Remember, sockets are bi-directional.
Or would you prefer that you do a sock.makefile('r') on it first?
Actually that seems like a nice solution to that. Forget the statement
above. I answered my own question.

> The timeout would be in some
> convenient timeformat with enough granularity to satisfy most needs
> (tenth of seconds?). If the timeout is 'None' the call would be
> blocking.

I like that. But you should make it milliseconds since that is what
the select() and poll() actually take. (Although for the project I am
working on, I will probably only set it for 5-10 MINUTES :) )

> It will return a list of (fileobject, string) pairs for
> those fileobjects that have one or multiple events pending, or 'None'
> if there are no pending events on any of the fileobjects.

Sounds reasonable. Clean, clear, easy to parse return!

> If you have poll(), the implementation is quite straight-forward. If
> you only have select(), you have to construct the bitmasks from the
> filelist information (which shouldn't be too hard).

The problem with poll() is that on some platforms, it handles
sockets, pipes, and files differently than select(). But I think
that the C code should be able to select which one you wish
to use via a #define statement when you do the compile.

Lance Ellinghouse
lance@markv.com