lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Thu, Jan 26, 2006 at 05:20:12PM -0500, Diego Nehab wrote:
> There are at least two nasty reasons for LuaSocket's socket.select not
> to work well with the file library.
> 
> First, on Win32, the select function call can only be used with sockets
> (sockets are not even file descriptors). Getting this to work
> transparently would require creating threads, which I didn't consider
> reasonable.

Most things in Windows are ultimately based around events.  I'd expect
there to be some way to get a Windows event, triggered when there's data
on a socket (or free buffer space, etc).  These events can be waited on,
in the same fashion as select and file descriptors.  (Actually, it's
better: events implement mutexes, so you can include "a mutex being
unlocked" as one of the events, which is much harder in Unix with
select().)  Of course, it's not portable.

There may be no such way to get an event from a Windows "socket", though,
in which case the only solution is probably to have a back-end that uses
entirely native Windows APIs.

> Even on Unix, Lua uses stream functions (descriptors are not ANSI, I
> guess). Although we could use the non-ANSI fileno function (select is
> not ANSI either, so who cares?), mixing these things would require
> flushing the buffers etc.

When I want any level of control over files, I skip the stream functions
and use low level fd access instead.  Of course, that means I have to do
buffering myself.

-- 
Glenn Maynard