Skip to content
libevent2 support for newlisp
Common Lisp
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


The libevent module provides a wrapper on top of the libevent2 library.


  • Signals


; --------------------------------------------------------------------------
; Timers
; --------------------------------------------------------------------------

(libevent:set-interval 10
  (fn () (println "Another 10ms have passed!")))



(setf socket (net-connect "" 80))
(setf buffer "")

; Wait until socket is write-ready
(libevent:watch-once socket libevent:WRITE
  (fn (fd e id)
    ; send HTTP request
    (write socket "GET / HTTP/1.0\r\n\r\n")

    ; wait for response
    (libevent:watch socket libevent:READ
      (fn (fd e id , buf bytes)
        ; read to local buffer
        (setf bytes (read fd buf 4096))
        (if bytes
          ; write to global buffer
          (write buffer buf)
          ; kill watcher and stop loop
            (libevent:unwatch id)

(println buffer)



(setf html "")

(define (on-read data)
  (write html data))

(define (on-event ev data)
    ((libevent:masks? ev libevent:BUFFER_EOF)
     (write html data)
     (println "Disconnected")
    ((libevent:masks? ev libevent:BUFFER_ERROR)
     (println "An error occurred")
    ((libevent:masks? ev libevent:BUFFER_TIMEOUT)
     (println "Timed out")

(or (setf socket (net-connect "" 80))
    (throw-error "Unable to connect"))

(setf buffer (libevent:make-buffer socket (regex-comp "[\r\n]+" 4) on-read on-event))
(libevent:buffer-send buffer "GET / HTTP/1.0\r\n\r\n")

(println html)


Copyright (C) 2012 "Jeff Ober"

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

You can’t perform that action at this time.