[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Why no select in luasocket ?
- From: Edgar Toernig <froese@...>
- Date: Sun, 04 Feb 2001 04:41:04 +0100
Diego Nehab wrote:
> > > > Why isn't there select() in luasocket?
> > > The only use of select by a script would to find out which of several
> > > sockets is ready for a given operation, thus alowing multiplexing. The
> > > library provides poll for that, and soon multi-threading within Lua will
> > > render this use less important.
> > Oh please, don't shoot pthreads at this. Is it that difficult to add
> > for example a wait function that gets a list of sockets? Polling is
> > nearly useless for anything but embedded systems or DOS. And timeouts
> > add an artificial latency that only some applications may tolerate.
> Oh please, better your tone. Some of us that are not native english
> speakers might get offended by the (hopefully) aparent sarcasm of your
I'm sorry. It was not in my intend to offend anyone. I'm not a native
english speaker myself and I've "honestly" no clue of what is offensive
in that paragraph. Is it the "don't shoot pthreads"? That's because I
saw too much simple problems being solved with pthreads.
Or is it the question "Is it that difficult..."? It was really just meant
as that, a question if it is that difficult to implement. I see no
obvious problems at least on Unix systems.
And about the two statements ...
> Try also being less categorical with your statements, lest they prove
If you think they are wrong then correct/flame/shoot/make an idiot of me.
> I understand the point you are trying to make, and I will think about a
> nice and clean way to implement select. It is not as obvious at it may
> seem, but then I am not God. See, I don't like select and I don't want
> to use the same interface to the functionality it provides. Do you have
> any suggestion (besides running toLua in /usr/include)?
Hmm... you don't like the interface... I made a different interface
for some app. A register function that gets an fd and a callback function.
And then a generic wait with only a timeout. The wait will select on
all registered fds and will call the callback of the fd if something
Or another one: simulate an event queue. You register fds. The next-
event function selects if no events are present and then builds events
on the select result. (This version may get problems because it
The question is: is it easier to export select and make the register/wait
in the highlevel or to implement it completely in C?
If you want something really different I guess you have to switch to
asynch io and completion signals. But that's IMHO even uglier, less
portable and much more difficult to implement.
> > > If there is anything you can't do with the current API, please clarify
> > > and I will try to help.
> > I only had a short look on luasocket but I would say: wait for any one
> > of two sockets to become readable ;-)
> That has already been said, by me. If you take better look, you will see
> that LuaSocket was created mainly to be used on the client side. The
> original idea was to provide support for for HTTP, SMTP and FTP.
> Server-side support is being improved with time.
For a single connection everything _is_ there. Select on one fd is like
your poll. It's only necessary if you really want to handle multiple
fds. That's what I wanted to say with "wait for two" ;) And trying to
solve this with "read with small timeout and poll all others" is IMHO
just an ugly hack.