lua-users home
lua-l archive

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



On Jan 29, 2005, at 08:33, Diego Nehab wrote:

    * everytime you want to do I/O, you should do so politely. That is,
    the socket has a timeout of 0. If you see a timeout, then yield.

One thing that I would like though, is to achieve this somewhat "transparently":

	local aConnection = aServer.accept()
	local anHandler = ConnectionHandler.new( aConnection )

	anHandler.spawn( anHandler.run() );

Somewhere else in ConnectionHandler:

local function run()
    local anInput = BufferedInput.new( this.source() );

    while ( aLine = anInput.readLine() )

	    -- do stuff with "aLine"

    end
end

Somewhere else in BufferedInput:

local function readLine()
	local aString, aStatus = this.connection().receive( 2^10 )

	if aStatus == "timeout" then
		this.connection().yield()
	end

	return aString, aStatus
end

Thoughts how to pull this out LuaSocket, LTN12 and coroutines?

Cheers

--
PA, Onnay Equitursay
http://alt.textdrive.com/