[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Buffered reading in LuaSocket..
- From: Duck <duck@...>
- Date: Mon, 17 Mar 2008 15:03:25 +1100 (EST)
G'day folks. I want to combine the functionality of tcp:receive(number)
[i.e. receive number bytes of data] and tcp:receive('*l') [i.e. read the
next line, delimited by LF].
I want to be able to write a line-oriented TCP server (e.g. SMTP) without
being at the whim of the connecting client when it comes to line length.
How to do this (using blocking) in Lua?
How do I say "read up to Y bytes or the next LF character, whichever
comes first, with a timeout of X seconds" without having to wait for
the timeout to elapse before my tcp:receive() returns with partial data?
Would it be satisfactory to do something like this:
X = 5; Y = 1000
tcp:settimeout(X)
head = tcp:receive(1)
tcp:settimeout(0)
tail = tcp:receive(Y-1)
thus assuming that in a line-based protocol with short lines, each line
tends to become readable at once? Or would something more esoteric be
required/desired, such as two one-byte reads each using up half of the
timeout, followed by a "get what's left in one go?"
All advice gladly accepted.