Hash :
53e79410
Author :
Thomas de Grivel
Date :
2017-04-10T17:41:17
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
(in-package :cffi-epoll)
(defcfun ("epoll_create" c-epoll-create) :int
(size :int))
(defun epoll-create (size)
(let ((fd (c-epoll-create size)))
(when (< fd 0)
(error-errno "epoll-create"))
fd))
(defcunion epoll-data
(ptr :pointer)
(fd :int)
(u32 uint32-t)
(u64 uint64-t))
(defcstruct epoll-event
(events uint32-t)
(data (:union epoll-data)))
(defcfun ("epoll_ctl" c-epoll-ctl) :int
(epfd :int)
(op :int)
(fd :int)
(event (:pointer (:struct epoll-event))))
(defun epoll-ctl (epfd op fd events data)
(with-foreign-object (evt '(:struct epoll-event))
(setf (foreign-slot-value evt '(:struct epoll-event) 'events) events
(foreign-slot-value evt '(:struct epoll-event) 'data) data)
(let ((r (c-epoll-ctl epfd op fd evt)))
(when (< r 0)
(error-errno "epoll_ctl"))
r)))
(defcfun ("epoll_wait" c-epoll-wait) :int
(epfd :int)
(events (:pointer (:struct epoll-event)))
(maxevents :int)
(timeout :int))
(defun epoll-wait (epfd &optional (maxevents 64) (timeout -1))
(with-foreign-object (events '(:struct epoll-event) maxevents)
(c-epoll-wait )))