lua-users home
lua-l archive

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


I cheat in a bad way by using "ioctl(fd, FIONREAD, &charin);" to avoid blocking.

All the lua system I build now have this function for only reading what's available.

I'll accept my public embarrassment now... ;-)

-joe

On Sat, Nov 15, 2008 at 7:07 PM, Sam Roberts <vieuxtech@gmail.com> wrote:
On Mon, Nov 10, 2008 at 2:05 AM, Jerome Vuarand
<jerome.vuarand@gmail.com> wrote:
> 2008/11/10 Sam Roberts <vieuxtech@gmail.com>:
>> LuaSocket doesn't have an obvious way to read whatever data is
>> available from a socket, if it isn't line delimited or of a known
>> size. I found a way, but it seems unnecessarily obscure.

> I think you can simply use the "*a" pattern to do what you asked for.
> It works just like the code you proposed, except it's not limited to a
> fixed amount of bytes and it properly handles the prefix parameter
> (which you don't). For example:

Btw, for any thinking of using *a for this, it can also use all
available memory and cpu, taking your machine to its knees before
aborting! You might not notice at first.

Anyhow, a client writing data sufficiently fast that the receiving
peer always has data available in the tcp/ip stack's receive buffer
will cause the receiving luasocket to always be able to read data, and
thus to accumulate the data in it's internal buffer without bound.

I really wish luasocket had an obvious equivalent to the underlying
BSD calls that just wrote or read a chunk of available data, and
returned how much was wrote or read. Its the simplest of use cases, it
should be the simplest to do.

Cheers,
Sam