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 Wesley Smith once stated:
> Use coroutines for this.  It's a much better model for handling event
> driven scripting situations where you need to maintain state and
> calculations between events.

  That's what I'm trying to use.  Sorry if I didn't make that clear.  

  The logic so far (which I haven't tested yet) is:

	C code			Lua code

	accept()
	lua_resume()
				blah
				blah
				blah socket:read() (which calls
					coroutine.yield())

	epoll_add(socket)
	ev = epoll_wait()
	if (ev.read) collect data
	if (enough data)
		lua_resume()
				blah
				blah
				socket:write() (coroutine.yield())

	ev = epoll_wait()
	if (can-write-data)
	{
	  write data
	  if no more data
		lua_resume()
	}

				...
				thread.exit() (coroutine.yield())

	epoll_remove(socket)
	close(socket)
	free(luathread)

  -spc (Hope that makes some sense ... )