source reactor.lsp
Module: Reactor
Author: Jeff Ober
Version: 0.1
Location: reactor.lsp
Event-based I/O processing with libevent
Reactor uses libevent to provide event-based I/O handling in newLISP.- § -
Reactor:init
syntax: (Reactor:init [int-callback-id])
parameter: int-callback-id - optional; the numeric callback id
Initializes the module. Due to newLISP's limitation of 16 function pointer slots, a callback number may be passed to override the default (0) when using this in conjunction with other libraries that might compete for slots. This must only be done once per session - the same callback may be used for any number of reactors.- § -
Reactor:make-reactor
syntax: (Reactor:make-reactor)
return: a reactor handle
Creates a new reactor and returns an active reactor handle.- § -
Reactor:kill-reactor
syntax: (Reactor:kill-reactor int-reactor)
parameter: int-reactor - an active reactor handle
Terminates the reactor and frees up memory. This does *not* free up events. It is the responsibility of the caller to retain event handls and pass them to Reactor:kill-event in order to free up events *before* calling Reactor:delete.- § -
Reactor:run-reactor
syntax: (Reactor:run-reactor int-reactor)
parameter: int-reactor - an active reactor handle
return: returns true on success, nil otherwise
Runs the I/O loop, processing events until all events complete or Reactor:break-loop is called.- § -
Reactor:stop-reactor
syntax: (Reactor:stop-reactor int-reactor)
parameter: int-reactor - an active reactor handle
return: returns true on success, nil otherwise
Schedules the loop to terminate after the next event has completed. The reactor may continue to be used.- § -
Reactor:make-event
syntax: (Reactor:make-event int-reactor int-fd [fn-on-read [fn-on-write [fn-on-error [int-timeout]]]])
parameter: int-reactor - an active reactor handle
parameter: int-fd - an open file or socket descriptor
parameter: fn-on-read - optional; a function to call when the descriptor is readable
parameter: fn-on-write - optional; a function to call when the descriptor is writable
parameter: fn-on-error - optional; a function to call when an error condition occurs (a signal or timeout)
parameter: int-timeout - optional; timeout in seconds
return: a new, active event handle
Builds a new event to monitor file descriptor int-fd. The function prototype for a callback is (f file-descriptor event-handle Reactor-context)- § -
Reactor:kill-event
syntax: (Reactor:kill-event int-event)
parameter: int-event - the event handle of the event to stop monitoring
return: returns true on success, nil on failure
Deletes an event and frees its memory.- § -
Reactor:make-timer
syntax: (Reactor:make-timer int-reactor fn-cb int-timeout [int-usec])
parameter: int-reactor - an active reactor handle
parameter: fn-cb - a function to call
parameter: int-timeout - the number of seconds before execution
Schedules a one-time event for fn-cb to be called after int-timeout ms.- § -
Reactor:kill-timer
syntax: (Reactor:kill-timer int-timer)
parameter: int-timer - an active timer handle
Halts a timer and frees its memory. This is an alias of kill-event.- ∂ -
generated with newLISP and newLISPdoc