lua-users home
lua-l archive

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


It was thus said that the Great Roberto Ierusalimschy once stated:
> > 1) The constant LUA_BUFFERSIZE is not available in Lua.  There should be a
> > constant, io.BUFFERSIZE, defined to be this value.  There are instances
> > where this would be nice to have.
> 
> What for?

  So I have this event driven network driver [1] where I can use Lua
coroutines to handle a TCP [2] or TLS [3] connections (both client and
server).  I also have code that turns such a connection into an object that
looks like a Lua file object [4] so that I can do things like:

	line = conn:read("l")
	raw  = conn:read(128)
	linecrlf = conn:read("L")

  I can't just wrap these up in a FILE* because that abstraction doesn't
lend itself to event driven programming.  If I could, I would have, but it
doesn't work, so I had to write this code.

  As it stands right now, it does *NO* buffering [5].  It would be nice to
support buffering [6] but it's hard to know what the default amount to
buffer is, hence the request for io.BUFFERSIZE.  Right now, all the code is
in pure Lua, I would hate to have to drop to C for just one constant.

  -spc (Does that make sense?)

[1]	https://github.com/spc476/lua-conmanorg/blob/master/lua/nfl.lua

[2]	https://github.com/spc476/lua-conmanorg/blob/master/lua/nfl/tcp.lua

[3]	https://github.com/spc476/lua-conmanorg/blob/master/lua/nfl/tls.lua

[4]	https://github.com/spc476/lua-conmanorg/blob/master/lua/net/ios.lua

[5]	The default setvbuf() implementation I have is:

		local function setvbuf()
		  return true
		end
	
	Which is misleading, but it will still work, just not to the extent
	that the programmer is expecting it to.  By extension, the default
	flush() routine is:

		local function flush()
		  return true
		end

	Because ... well ... nothing is buffered so there's nothing to
	flush.

[6]	Because the IO wrapper [4] is really not limited to just network
	stuff---it could be used for anything that you want to act as a
	FILE* but can't shoehorn into that, like maybe memory, or a
	compressed file or event driven network IO.