[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Can there be a better way of doing non-blocking data reads with LuaSocket?
- From: "Sam Roberts" <vieuxtech@...>
- Date: Wed, 12 Nov 2008 08:23:02 -0800
On Wed, Nov 12, 2008 at 12:50 AM, Diego Nehab <diego@tecgraf.puc-rio.br> wrote:
>> I wasn't too worried about that. I'm not really sure what the use case
>> for that parameter is, generally, but I particularly can't see why
>> you'd want a prefix inserted into essentially random spots in a TCP
>> stream!
>
> Think about reading a line pattern in non-blocking mode,
> i.e., with 0 timeout. You don't know if the line will come
> in one function call or if it will be split into several
> function calls. You don't know if it will fit in the buffer
> or not, so you can't accumulate it there. So passing the
> partial result from the previous call into the next call
> makes sure that when the call finally succeeds, you have
> your entire line in one place. I think it is pretty
> convenient. If there is a bug on this idea, let me know and
> I will fix it.
Ah, no, that makes a lot of sense to be able to avoid string
concatenation overhead.
My impression was that it was a way to do things like add "server: "
to all lines read from the server.
Sam