Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Libevent wrapper in Common Lisp.

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 README.rst
Octocat-spinner-32 cl-event.asd
Octocat-spinner-32 cl-event.lisp
Octocat-spinner-32 event-ffi.lisp
Octocat-spinner-32 packages.lisp
Octocat-spinner-32 test.lisp
Octocat-spinner-32 utility.lisp
README.rst

cl-event

Usage

Beginning Your Code

To use this cl-event, start out with creating a callback and a stream:

(in-package :event)
(defun my-callback (s)
  ...)

(defvar s ( ... open stream ... ))

; initialize libevent
(event-init)

and then either explicitly calling functions from the API or using a convenience function instead.

The Middle Bits

Option 1: Explicit Calls

Here are the functions that you'll need to call in order to create an event and have it scheduled:

; create an instance of an event
(defvar e (make-instance 'event))
; associate event with a callback and a stream
(event-set e s (make-flags :ev-persist t) 'my-callback s)
; add event to libevent event-base
(event-add e)

Option 2: Using an Object

If you would rather use the convenience function add-event-callback, you won't need to manually instantiate an event as was illustrated in the "Explicit Calls" section.

Consider that we have defiend a CLOS object (elsewhere) containing a stream and other stuff called CONNECTION and a method called READ-CONNECTION that takes a CONNECTION object as argument. You can can implicitly create an event, set the callback on it, and then schedule the event with the the add-event-callback convenience function:

(add-event-callback (connection-stream connection)
  (make-flags :ev-persist t) 'read-connection connection)

Finishing Up

; main loop of libevent, calls my-callback (or read-connection) as defined
above whenever there is anything to read on the given stream
(event-dispatch)
Something went wrong with that request. Please try again.