lua-users home
lua-l archive

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


On Thu, Mar 15, 2012 at 3:59 PM, Jay Carlson <nop@nop.com> wrote:
>> This is the most basic usage of the BSD socket API, and while not
>> directly supported by luasocket, you can do it like this:
>>
>> https://github.com/sam-github/swirl/blob/master/lua/sockext.lua, see line 39.
>
> This works because elsewhere sockets are set to have a timeout of 0.

Of course, if you don't set a timeout, you're going to block.

> (As a reminder, the select() system call may be misinformed about how
> ready a particular fd is, so you need to be reading/writing in
> non-blocking mode anyway. Regardless of what POSIX says.)

I was pretty sure POSIX never specified select(), but I just checked,
and there was a 2001 version, and if finally fixed this. I'd thought
POSIX was moribund, ever since the .1g attempt failed.

Anyhow, most network programming texts talk about the importance of
Jay's point. If you expect not to block, you need to set non-blocking,
as well as use select (poll, epoll, ...).

Cheers,
Sam