> 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