lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index] wrote:
> >From the manual:
>   '*a': reads from the socket until the connection is closed.
> This is very different from returning only data that is 
> available at the time receive is called - receive("*a") will 
> block until the socket is closed, am I right ?

Yeah, you're right, I misread the manual. But setting a timeout to 0
will return whatever bytes are already received.

> Ah, ok - this makes a lot of sense, and this is where I made 
> my mistake!
> I am not using, but instead I'm passing the 
> file descriptors returned by socket:getfd() to my own 
> select() in C code - oblivious of the fact that 
> does a bit more then a bare
> libc-select() call. Did I miss something in the documentation ?

Mixing a low level and a high level API is never a good idea, unless
they are designed for that purpose. You can call LuaSocket functions
from C code easily, thus keeping the ability to use your sockets
directly from Lua. And with non-blocking sockets you will have the
behaviour you expect. You can roll you own LuaSocket, but if that's just
to avoid calling socket.settimeout it's not the easiest solution.