Copas
Coroutine Oriented Portable Asynchronous Services for Lua

Reference

Copas functions are separated in two groups.

The first group is relative to the use of the dispatcher itself and are used to register servers and to execute the main loop of Copas:

  • copas.addserver(server, handler[, timeout])
    Adds a new server and its handler to the dispatcher using an optional timeout.
    server is a LuaSocket server socket created using socket.bind().
    handler is a function that receives a LuaSocket client socket and handles the communication with that client.
    timeout is the timeout for blocking I/O in seconds.
  • copas.loop(timeout)
    Starts the Copas infinite loop accepting client connections for the registered servers and handling those connections with the corresponding handlers. Every time a server accepts a connection, Copas calls the associated handler passing the client socket returned by accept(). The timeout parameter is optional.
  • copas.step(timeout)
    Executes one copas iteration accepting client connections for the registered servers and handling those connections with the corresponding handlers. When a server accepts a connection, Copas calls the associated handler passing the client socket returned by accept(). The timeout parameter is optional.

The second group is used by the handler functions to exchange data with the clients:

  • copas.flush(skt)
    Flushes a client write buffer. copas.flush() is called from time to time by copas.loop() but it may be necessary to call it from the handler function.
  • copas.receive(skt, pattern)
    Reads data from a client socket according to a pattern just like LuaSocket socket:receive(). The Copas version does not block and allows the multitasking of the other handlers.
  • copas.send(skt, data)
    Sends data to a client socket just like socket:send(). The Copas version is buffered and does not block, allowing the multitasking of the other handlers.
  • copas.wrap(skt)
    Wraps a LuaSocket socket and returns a Copas socket that implements LuaSocket's API but use Copas' methods copas.send() and copas.receive() automatically.

Valid XHTML 1.0!

$Id: reference.html,v 1.10 2005/05/11 15:29:25 carregal Exp $