Fix sequence type derivation in the presence of negation types.
[sbcl.git] / contrib / sb-bsd-sockets / misc.lisp
blob66152ff5c0ae144df9acaff4f7aafbbb0121973e
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 #-win32
13 (defmethod non-blocking-mode ((socket socket))
14 (let ((fd (socket-file-descriptor socket)))
15 (sb-alien:with-alien ((arg integer))
16 (> (logand
17 (sockint::fcntl fd sockint::f-getfl arg)
18 sockint::o-nonblock)
19 0))))
21 #+win32
22 (defmethod non-blocking-mode ((socket socket))
23 (slot-value socket 'non-blocking-p))
25 #-win32
26 (defmethod (setf non-blocking-mode) (non-blocking-p (socket socket))
27 (declare (optimize (speed 3)))
28 (let* ((fd (socket-file-descriptor socket))
29 (arg1 (the (signed-byte 32) (sockint::fcntl fd sockint::f-getfl 0)))
30 (arg2
31 (if non-blocking-p
32 (logior arg1 sockint::o-nonblock)
33 (logand (lognot sockint::o-nonblock) arg1))))
34 (when (= (the (signed-byte 32) -1)
35 (the (signed-byte 32)
36 (sockint::fcntl fd sockint::f-setfl arg2)))
37 (socket-error "fcntl"))
38 non-blocking-p))
40 #+win32
41 (defmethod (setf non-blocking-mode)
42 (non-blocking-p (socket socket))
43 (declare (optimize (speed 3)))
44 (setf (slot-value socket 'non-blocking-p)
45 (when non-blocking-p t))
46 (let ((fd (socket-file-descriptor socket)))
47 (when (= (the (signed-byte 32) -1)
48 (the (signed-byte 32)
49 (sockint::ioctl fd sockint::FIONBIO (if non-blocking-p 1 0))))
50 (socket-error "ioctl(FIONBIO)"))
51 (when non-blocking-p t)))