[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Can there be a better way of doing non-blocking data reads with LuaSocket?
- From: "Sam Roberts" <vieuxtech@...>
- Date: Sat, 15 Nov 2008 16:07:43 -0800
On Mon, Nov 10, 2008 at 2:05 AM, Jerome Vuarand
> 2008/11/10 Sam Roberts <firstname.lastname@example.org>:
>> 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.