Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added examples directory and wrapped ##epoll#epoll_ctl in an exported…

… function
  • Loading branch information...
commit 3f3a6c41c1a566f4e5c6c5ea0dc43cbe05667012 1 parent 93c3abf
David Reynolds authored
Showing with 23 additions and 7 deletions.
  1. +2 −0  .gitignore
  2. +6 −0 examples/echo/echo.scm
  3. +15 −7 src/server.scm
2  .gitignore
View
@@ -1 +1,3 @@
*.swp
+*.o
+*.so
6 examples/echo/echo.scm
View
@@ -0,0 +1,6 @@
+(require 'rooster)
+
+(define (handler fd buf)
+ (send-to-client fd buf))
+
+(run-rooster handler)
22 src/server.scm
View
@@ -12,7 +12,11 @@
(declare
(uses tcp)
- (export run-rooster send-to-client send-to-all remove-client))
+ (export run-rooster
+ send-to-client
+ send-to-all
+ remove-client
+ rooster-epoll-ctl))
;; required for make-hash-table (compiled vs. interpreted)
(require 'srfi-69)
@@ -49,6 +53,10 @@ EOF
;; use foreign-safe-lambda because this C function calls back into Chicken
(define ##epoll#epoll_wait (foreign-safe-lambda void "_epoll_wait" int int))
+;; exported wrapper around epoll_ctl
+(define (rooster-epoll-ctl flags fd iostate)
+ (##epoll#epoll_ctl epfd flags fd iostate))
+
;; define this here because it's not exported by tcp.scm
(define setnonblock (foreign-lambda* bool ((int fd))
"int val = fcntl(fd, F_GETFL, 0);"
@@ -90,7 +98,7 @@ EOF
(set! fd-list (filter-out-fd fd))
(hash-table-remove fd-write-table fd)
(hash-table-remove fd-read-table fd)
- (##epoll#epoll_ctl epfd _EPOLL_CTL_DEL fd 0)
+ (rooster-epoll-ctl _EPOLL_CTL_DEL fd 0)
(##net#close fd))
(define (send-to-client fd str)
@@ -100,7 +108,7 @@ EOF
(let ((buf (hash-table-ref fd-write-table fd)))
(hash-table-set! fd-write-table fd (string-append buf str)))
- (##epoll#epoll_ctl epfd _EPOLL_CTL_MOD fd _WRITE))
+ (rooster-epoll-ctl _EPOLL_CTL_MOD fd _WRITE))
(define (send-to-all buf sender-fd)
(let fdloop ((fds fd-list))
@@ -117,7 +125,7 @@ EOF
(init-client fd)
(set! fd-list (cons fd fd-list))
(send-to-client fd "Simple Echo Server\n\n")
- (##epoll#epoll_ctl epfd _EPOLL_CTL_ADD fd _WRITE)))
+ (rooster-epoll-ctl _EPOLL_CTL_ADD fd _WRITE)))
(define (write-handler fd)
;; epoll tells us to write to socket
@@ -131,7 +139,7 @@ EOF
(hash-table-set! fd-write-table fd "")
;; update epoll to watch for a read event on this fd
- (##epoll#epoll_ctl epfd _EPOLL_CTL_MOD fd _READ))
+ (rooster-epoll-ctl _EPOLL_CTL_MOD fd _READ))
(define (read-loop fd maxlen)
(let ((rbuf (make-string maxlen)))
@@ -153,7 +161,7 @@ EOF
(let* ((len 4096)
(buf (read-loop fd len)))
(_RequestHandler fd buf)
- (##epoll#epoll_ctl epfd _EPOLL_CTL_MOD fd _WRITE)))
+ (rooster-epoll-ctl _EPOLL_CTL_MOD fd _WRITE)))
(define (fd-event-list-handler ls)
;; takes a list of (fd . events) pairs
@@ -188,7 +196,7 @@ EOF
(set! epfd (##epoll#epoll_create))
(set! _RequestHandler request-handler)
- (##epoll#epoll_ctl epfd _EPOLL_CTL_ADD sfd _READ)
+ (rooster-epoll-ctl _EPOLL_CTL_ADD sfd _READ)
(let loop ()
(##epoll#epoll_wait epfd 200)
Please sign in to comment.
Something went wrong with that request. Please try again.