diff --git a/cffi-unistd.lisp b/cffi-unistd.lisp
index b26355d..b0fb5ee 100644
--- a/cffi-unistd.lisp
+++ b/cffi-unistd.lisp
@@ -671,21 +671,25 @@ without changing the file pointer. Returns number of bytes written."
(push fd result)))
result))
+(defun fd< (a b)
+ (< (the file-descriptor a) (the file-descriptor b)))
+
(defmacro with-selected ((readfds &optional writefds exceptfds timeout)
(readfds-var writefds-var exceptfds-var)
&body body)
- (let ((g-readfds (gensym "R-"))
- (g-writefds (gensym "W-"))
- (g-exceptfds (gensym "E-"))
- (nfds (gensym "N-"))
- (fd-set-read (gensym "FDS-R-"))
- (fd-set-write (gensym "FDS-W-"))
- (fd-set-except (gensym "FDS-E-"))
+ (let ((g-readfds (gensym "READFDS-"))
+ (g-writefds (gensym "WRITEFDS-"))
+ (g-exceptfds (gensym "EXCEPTFDS-"))
+ (nfds (gensym "NFDS-"))
+ (fd-set-read (gensym "FD-SET-READ-"))
+ (fd-set-write (gensym "FD-SET-WRITE-"))
+ (fd-set-except (gensym "FD-SET-EXCEPT-"))
(tv (gensym "TV-")))
`(let ((,g-readfds ,readfds)
(,g-writefds ,writefds)
(,g-exceptfds ,exceptfds)
(,nfds 0))
+ (declare (type fixnum ,nfds))
(cffi:with-foreign-objects ((,fd-set-read '(:struct fd-set))
(,fd-set-write '(:struct fd-set))
(,fd-set-except '(:struct fd-set))
@@ -697,20 +701,22 @@ without changing the file pointer. Returns number of bytes written."
(when ,timeout
(seconds-to-timeval ,timeout ,tv))
(dolist (fd ,g-readfds)
- (when (< ,nfds fd) (setq ,nfds fd)))
+ (when (fd< ,nfds fd) (setq ,nfds fd)))
(dolist (fd ,g-writefds)
- (when (< ,nfds fd) (setq ,nfds fd)))
+ (when (fd< ,nfds fd) (setq ,nfds fd)))
(dolist (fd ,g-exceptfds)
- (when (< ,nfds fd) (setq ,nfds fd)))
+ (when (fd< ,nfds fd) (setq ,nfds fd)))
(incf ,nfds)
(handler-case
(select ,nfds ,fd-set-read ,fd-set-write ,fd-set-except
(if ,timeout ,tv (null-pointer)))
(errno:errno-error (condition)
- (when (= errno:+eintr+ (errno:errno-error-errno condition))
+ (when (= errno:+eintr+ (the fixnum
+ (errno:errno-error-errno condition)))
(continue))))
(let ((,readfds-var (fd-set-filter ,g-readfds ,fd-set-read))
(,writefds-var (fd-set-filter ,g-writefds ,fd-set-write))
(,exceptfds-var (fd-set-filter ,g-exceptfds ,fd-set-except)))
- (declare (ignorable ,readfds-var ,writefds-var ,exceptfds-var))
+ (declare (ignorable ,readfds-var ,writefds-var ,exceptfds-var)
+ (type list ,readfds-var ,writefds-var ,exceptfds-var))
(return (progn ,@body))))))))