1 (in-package :sb-bsd-sockets
)
3 ;;; Miscellaneous things, placed here until I can find a logically more
4 ;;; coherent place to put them
6 ;;; I don't want to provide a complete interface to unix file
7 ;;; operations, for example, but being about to set O_NONBLOCK on a
8 ;;; socket is a necessary operation.
10 ;;; XXX bad (sizeof (int) ==4 ) assumptions
12 (defgeneric non-blocking-mode
(socket)
13 (:documentation
"Is SOCKET in non-blocking mode?"))
16 (defmethod non-blocking-mode ((socket socket
))
17 (let ((fd (socket-file-descriptor socket
)))
18 (sb-alien:with-alien
((arg integer
))
20 (sockint::fcntl fd sockint
::f-getfl arg
)
25 (defmethod non-blocking-mode ((socket socket
)) 0)
27 (defgeneric (setf non-blocking-mode
) (non-blocking-p socket
)
28 (:documentation
"Put SOCKET in non-blocking mode - or not, according to NON-BLOCKING-P"))
31 (defmethod (setf non-blocking-mode
) (non-blocking-p (socket socket
))
32 (declare (optimize (speed 3)))
33 (let* ((fd (socket-file-descriptor socket
))
34 (arg1 (the (signed-byte 32) (sockint::fcntl fd sockint
::f-getfl
0)))
37 (logior arg1 sockint
::o-nonblock
)
38 (logand (lognot sockint
::o-nonblock
) arg1
))))
39 (when (= (the (signed-byte 32) -
1)
41 (sockint::fcntl fd sockint
::f-setfl arg2
)))
42 (socket-error "fcntl"))
46 (defmethod (setf non-blocking-mode
) (non-blocking-p (socket socket
)) 0)
47 ;; (sb-alien:with-alien ((mode (unsigned 32)))
48 ;; (if non-blocking-p (setf mode 1))
49 ;; (ioctlsocket socket FIONBIO mode)))