Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sysread/nl-event
libevent2 support for newlisp
https://github.com/sysread/nl-event
Last synced: about 2 months ago
JSON representation
libevent2 support for newlisp
- Host: GitHub
- URL: https://github.com/sysread/nl-event
- Owner: sysread
- Created: 2012-12-31T18:56:24.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2013-01-04T19:55:32.000Z (about 12 years ago)
- Last Synced: 2023-03-23T22:19:34.928Z (almost 2 years ago)
- Language: Common Lisp
- Size: 146 KB
- Stars: 4
- Watchers: 6
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
nl-event
================================================================================The libevent module provides a wrapper on top of the [libevent2
library](http://libevent.org/).Todo
--------------------------------------------------------------------------------
* SignalsTimers
--------------------------------------------------------------------------------
; --------------------------------------------------------------------------
; Timers
; --------------------------------------------------------------------------
(libevent:init)(libevent:set-interval 10
(fn () (println "Another 10ms have passed!")))(libevent:run)
Events
--------------------------------------------------------------------------------
(libevent:init)
(setf socket (net-connect "www.google.com" 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
(begin
(libevent:unwatch id)
(libevent:stop)))))))(libevent:run)
(println buffer)Buffers
--------------------------------------------------------------------------------
(libevent:init)
(setf html "")
(define (on-read data)
(write html data))
(define (on-event ev data)
(cond
((libevent:masks? ev libevent:BUFFER_EOF)
(write html data)
(println "Disconnected")
(libevent:stop))
((libevent:masks? ev libevent:BUFFER_ERROR)
(println "An error occurred")
(libevent:stop))
((libevent:masks? ev libevent:BUFFER_TIMEOUT)
(println "Timed out")
(libevent:stop))))
(or (setf socket (net-connect "www.google.com" 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")
(libevent:run)
(println html)License
--------------------------------------------------------------------------------
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.