lua-users home
lua-l archive

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


On Tue, Nov 11, 2008 at 1:24 PM, Diego Nehab <diego@tecgraf.puc-rio.br> wrote:
>> Hi - I have an application where I would like to have a timeout for
>> stdin - I know with luasocket, select can be used for timeouts on
>> network sockets - any way of doing this for stdin?
>
> Please check the thread at
>
>    http://lua-users.org/lists/lua-l/2008-06/msg00074.html

This is officially a FAQ, why not add it to the docs?

Jim - I think the below is more concise than the 2008 thread.

Diego - I read through the buffer code... still no idea what dirty() is for.

---

Date: Wed, 4 Oct 2006 15:45:58 -0400 (EDT)
From: Diego Nehab <diego@tecgraf.puc-rio.br>
To: Lua list <lua@bazar2.conectiva.com.br>
Subject: Re: LuaSocket - can I select on descriptors that are not
socket objects?

Hi,

Sorry to break the thread, but my message bounced and I had
already erased the post. :/

> - It looks like socket.select() only takes a socket object, but I would
>  like to select on other file descriptors. Will I need to create a
>  fd-wrapper object in order to do this?

Quick dirty undocumented solution: Unix just use a table
that has a getfd() and dirty() methods (check source code,
dirty() is to support input buffering). On Windows, this
won't work. Not my fault, though. Sockets are not file
descriptors on Windows and select() only works with sockets.

> - It looks like tcp() can only create a new socket descriptor. If my lua
>  code is called from inetd, fd 0 will be a connected socket. It would
>  be nice to be able to call socket.tcp() with the descriptor of an
>  already connected socket.

Quick dirty undocumented solution: call setfd().

> - Also, I would like to integrate socket.select() with io.popen(), I
>  guess I will need to add io:fileno() and either a generic fd-wrapper
>  socket object, or a socket.pipe() that takes a fd, or a socket.popen()
>  that takes args like io.popen().

On Unix, as long as you have the fd, you are all set.