lev

2023-10-21

libev bindings for Common Lisp

Upstream URL

github.com/fukamachi/lev

Author

Eitaro Fukamachi

License

BSD 2-Clause
README

LEV

LEV is libev bindings for Common Lisp.

Usage

(ql:quickload :lev)

(cffi:defcallback stdin-cb :void ((evloop :pointer) (io :pointer) (revents :int))
  (declare (ignore revents))
  (format t "stdin ready~%")
  (lev:ev-io-stop evloop io))

(cffi:defcallback timeout-cb :void ((evloop :pointer) (timer :pointer) (revents :int))
  (declare (ignore timer revents))
  (format t "timeout~%")
  (lev:ev-break evloop lev:+EVBREAK-ONE+))

(let ((evloop (lev:ev-default-loop 0))
      (stdin-watcher (cffi:foreign-alloc '(:struct lev:ev-io)))
      (timeout-watcher (cffi:foreign-alloc '(:struct lev:ev-timer))))
  (unwind-protect
      (progn
        ;; initialize an io watcher, then start it
        ;; this one will watch for stdin to become readable
        (lev:ev-io-init stdin-watcher 'stdin-cb 0 lev:+EV-READ+)
        (lev:ev-io-start evloop stdin-watcher)

        ;; initialize a timer watcher, then start it
        ;; simple non-repeating 5.5 second timeout
        (lev:ev-timer-init timeout-watcher 'timeout-cb 5.5d0 0d0)
        (lev:ev-timer-start evloop timeout-watcher)

        (format t "running~%")
        (lev:ev-run evloop 0))
    (cffi:foreign-free stdin-watcher)
    (cffi:foreign-free timeout-watcher)))

Why not cl-ev?

We already have cl-ev for libev bindings, however I found there's some problems in it.

  • Wrapping with CLOS. It's bad for performance, obviously
  • Incomplete API
  • The author is inactive in Common Lisp world anymore

See Also

Author

Copyright

Copyright (c) 2014 Eitaro Fukamachi (e.arrows@gmail.com)

License

Licensed under the BSD 2-Clause License.

Dependencies (1)

  • cffi

Dependents (1)

  • GitHub
  • Quicklisp