From e8252cbede9a02fcda739592ec6db9b207882fff Mon Sep 17 00:00:00 2001 From: Stelian Ionescu Date: Tue, 7 Sep 2010 21:53:25 +0300 Subject: [PATCH] Move select() and struct timeval to LFP bindings --- src/libfixposix/ffi-functions.lisp | 35 +++++++++++++++++++++++++++++++++++ src/libfixposix/ffi-types.lisp | 18 ++++++++++++++++++ src/libfixposix/pkgdcl.lisp | 22 ++++++++++++++++++++++ src/multiplex/backend-select.lisp | 13 ++++++++----- src/syscalls/ffi-functions-unix.lisp | 35 +++-------------------------------- src/syscalls/ffi-types-unix.lisp | 15 --------------- src/syscalls/pkgdcl.lisp | 23 +++++++++++++++++++++++ 7 files changed, 109 insertions(+), 52 deletions(-) diff --git a/src/libfixposix/ffi-functions.lisp b/src/libfixposix/ffi-functions.lisp index a58e15a..be72b34 100644 --- a/src/libfixposix/ffi-functions.lisp +++ b/src/libfixposix/ffi-functions.lisp @@ -49,6 +49,41 @@ The two memory areas may overlap." (src :pointer) (count size-t)) + +;;;------------------------------------------------------------------------- +;;; File descriptor polling +;;;------------------------------------------------------------------------- + +(defcfun (select "lfp_select") :int + "Scan for I/O activity on multiple file descriptors." + (nfds :int) + (readfds :pointer) + (writefds :pointer) + (exceptfds :pointer) + (timeout :pointer) + (sigmask :pointer)) + +(defun copy-fd-set (from to) + (memcpy to from size-of-fd-set) + to) + +(defcfun (fd-clr "lfp_fd_clr") :void + (fd :int) + (fd-set :pointer)) + +(defcfun (fd-isset "lfp_fd_isset") bool + (fd :int) + (fd-set :pointer)) + +(defcfun (fd-set "lfp_fd_set") :void + (fd :int) + (fd-set :pointer)) + +(defcfun (fd-zero "lfp_fd_zero") :void + (fd-set :pointer)) + + +;;;------------------------------------------------------------------------- ;;; Socket message readers ;;;------------------------------------------------------------------------- diff --git a/src/libfixposix/ffi-types.lisp b/src/libfixposix/ffi-types.lisp index 5ff7cb0..072641d 100644 --- a/src/libfixposix/ffi-types.lisp +++ b/src/libfixposix/ffi-types.lisp @@ -13,9 +13,12 @@ ;;; Simple POSIX types ;;;------------------------------------------------------------------------- +(ctype bool "bool") (ctype size-t "size_t") (ctype ssize-t "ssize_t") (ctype off-t "off_t") +(ctype time-t "time_t") +(ctype suseconds-t "suseconds_t") ;;;------------------------------------------------------------------------- @@ -108,6 +111,21 @@ ;;;------------------------------------------------------------------------- +;;; sys/select.h +;;;------------------------------------------------------------------------- + +(cstruct timeval "struct timeval" + "UNIX time specification in seconds and microseconds." + (sec "tv_sec" :type time-t) + (usec "tv_usec" :type suseconds-t)) + +(constant (fd-setsize "FD_SETSIZE")) + +(cstruct fd-set "fd_set" + (bits "fds_bits" :type :uint8 :count :auto)) + + +;;;------------------------------------------------------------------------- ;;; sys/wait.h ;;;------------------------------------------------------------------------- diff --git a/src/libfixposix/pkgdcl.lisp b/src/libfixposix/pkgdcl.lisp index 02a62f1..6eada55 100644 --- a/src/libfixposix/pkgdcl.lisp +++ b/src/libfixposix/pkgdcl.lisp @@ -25,9 +25,20 @@ #:size-of-pointer ;; POSIX Types + #:bool #:size-of-bool #:size-t #:size-of-size-t #:ssize-t #:size-of-ssize-t #:off-t #:size-of-off-t + #:time-t #:size-of-time-t + #:suseconds-t #:size-of-suseconds-t + + ;;;---------------------------------------------------------------------- + ;;; Struct definitions, slots and accessors + ;;;---------------------------------------------------------------------- + + ;; timeval + #:timeval #:size-of-timeval + #:sec #:usec ;;;---------------------------------------------------------------------- @@ -51,6 +62,9 @@ #:estale #:etime #:etimedout #:etxtbsy #:ewouldblock #:exdev #:ebug + ;; Select() + #:fd-setsize + ;; Waitpid() #:wnohang #:wuntraced @@ -70,6 +84,14 @@ #:memcpy #:memmove + ;; I/O Polling + #:select + #:copy-fd-set + #:fd-clr + #:fd-isset + #:fd-set + #:fd-zero + ;; Signals #:wifexited #:wexitstatus diff --git a/src/multiplex/backend-select.lisp b/src/multiplex/backend-select.lisp index a079a81..e43618e 100644 --- a/src/multiplex/backend-select.lisp +++ b/src/multiplex/backend-select.lisp @@ -19,7 +19,9 @@ (:default-initargs :fd-limit (1- isys:fd-setsize))) (defun allocate-fd-set () - (isys:fd-zero (foreign-alloc 'isys:fd-set))) + (let ((fd-set (foreign-alloc 'isys:fd-set))) + (isys:fd-zero fd-set) + fd-set)) (defmethod print-object ((mux select-multiplexer) stream) (print-unreadable-object (mux stream :type nil :identity nil) @@ -100,10 +102,11 @@ (when tmp-timeout (timeout->timeval tmp-timeout tv)) (isys:select (1+ max-fd) - read-fds - write-fds - except-fds - (if tmp-timeout tv (null-pointer))))) + read-fds + write-fds + except-fds + (if tmp-timeout tv (null-pointer)) + (null-pointer)))) (isys:ebadf () (return* (harvest-select-fd-errors rs ws max-fd)))) (harvest-select-events max-fd read-fds write-fds except-fds)))) diff --git a/src/syscalls/ffi-functions-unix.lisp b/src/syscalls/ffi-functions-unix.lisp index 062b5df..189fc3d 100644 --- a/src/syscalls/ffi-functions-unix.lisp +++ b/src/syscalls/ffi-functions-unix.lisp @@ -447,43 +447,14 @@ Return two values: the file descriptor and the path of the temporary file." ;;; File descriptor polling ;;;------------------------------------------------------------------------- -(defsyscall (select "select") :int +(defsyscall (select "lfp_select") :int "Scan for I/O activity on multiple file descriptors." (nfds :int) (readfds :pointer) (writefds :pointer) (exceptfds :pointer) - (timeout :pointer)) - -(defentrypoint fd-zero (fd-set) - (bzero fd-set size-of-fd-set) - (values fd-set)) - -(defentrypoint copy-fd-set (from to) - (memcpy to from size-of-fd-set) - (values to)) - -(deftype select-file-descriptor () - `(mod #.fd-setsize)) - -(defentrypoint fd-isset (fd fd-set) - (multiple-value-bind (byte-off bit-off) (floor fd 8) - (let ((oldval (mem-aref fd-set :uint8 byte-off))) - (logbitp bit-off oldval)))) - -(defentrypoint fd-clr (fd fd-set) - (multiple-value-bind (byte-off bit-off) (floor fd 8) - (let ((oldval (mem-aref fd-set :uint8 byte-off))) - (setf (mem-aref fd-set :uint8 byte-off) - (logandc2 oldval (ash 1 bit-off))))) - (values fd-set)) - -(defentrypoint fd-set (fd fd-set) - (multiple-value-bind (byte-off bit-off) (floor fd 8) - (let ((oldval (mem-aref fd-set :uint8 byte-off))) - (setf (mem-aref fd-set :uint8 byte-off) - (logior oldval (ash 1 bit-off))))) - (values fd-set)) + (timeout :pointer) + (sigmask :pointer)) ;;; FIXME: Until a way to autodetect platform features is implemented (eval-when (:compile-toplevel :load-toplevel :execute) diff --git a/src/syscalls/ffi-types-unix.lisp b/src/syscalls/ffi-types-unix.lisp index 0f07b81..bd4eb37 100644 --- a/src/syscalls/ffi-types-unix.lisp +++ b/src/syscalls/ffi-types-unix.lisp @@ -251,21 +251,6 @@ ;;;------------------------------------------------------------------------- -;;; sys/select.h -;;;------------------------------------------------------------------------- - -(cstruct timeval "struct timeval" - "UNIX time specification in seconds and microseconds." - (sec "tv_sec" :type time-t) - (usec "tv_usec" :type suseconds-t)) - -(constant (fd-setsize "FD_SETSIZE")) - -(cstruct fd-set "fd_set" - (bits "fds_bits" :type :uint8 :count :auto)) - - -;;;------------------------------------------------------------------------- ;;; Fcntl() ;;;------------------------------------------------------------------------- diff --git a/src/syscalls/pkgdcl.lisp b/src/syscalls/pkgdcl.lisp index 97dd943..00617c8 100644 --- a/src/syscalls/pkgdcl.lisp +++ b/src/syscalls/pkgdcl.lisp @@ -26,9 +26,21 @@ #:size-of-pointer ;; POSIX Types + #:bool #:size-of-bool #:size-t #:size-of-size-t #:ssize-t #:size-of-ssize-t #:off-t #:size-of-off-t + #:time-t #:size-of-time-t + #:suseconds-t #:size-of-suseconds-t + + ;;;---------------------------------------------------------------------- + ;;; Struct definitions, slots and accessors + ;;;---------------------------------------------------------------------- + + ;; timeval + #:timeval #:size-of-timeval + #:sec + #:usec ;;;---------------------------------------------------------------------- @@ -52,6 +64,9 @@ #:estale #:etime #:etimedout #:etxtbsy #:ewouldblock #:exdev #:ebug + ;; Select() + #:fd-setsize + ;; Waitpid() #:wnohang #:wuntraced @@ -71,6 +86,14 @@ #:memcpy #:memmove + ;; I/O Polling + ;; select() is wrapped + #:copy-fd-set + #:fd-clr + #:fd-isset + #:fd-set + #:fd-zero + ;; Signals #:wifexited #:wexitstatus -- 2.11.4.GIT