1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; indent-tabs-mode: nil -*-
3 ;;; --- FD mixin definitions
6 (in-package :io.streams
)
10 (defmethod close :around
((fd-mixin dual-channel-single-fd-mixin
)
12 (declare (ignore abort
))
14 (when (fd-of fd-mixin
)
15 (isys:%sys-close
(fd-of fd-mixin
))
16 (setf (fd-of fd-mixin
) nil
)))
18 ;;;; Get and Set O_NONBLOCK
20 (defun %get-fd-nonblock-mode
(fd)
21 (let ((current-flags (isys:%sys-fcntl fd nix
:f-getfl
)))
22 (logtest isys
:o-nonblock current-flags
)))
24 (defun %set-fd-nonblock-mode
(fd mode
)
25 (let* ((current-flags (isys:%sys-fcntl fd nix
:f-getfl
))
27 (logior current-flags isys
:o-nonblock
)
28 (logandc2 current-flags isys
:o-nonblock
))))
29 (when (/= new-flags current-flags
)
30 (isys:%sys-fcntl fd isys
:f-setfl new-flags
))
33 (defmethod input-fd-non-blocking ((fd-mixin dual-channel-fd-mixin
))
34 (%get-fd-nonblock-mode
(fd-of fd-mixin
)))
36 (defmethod (setf input-fd-non-blocking
) (mode (fd-mixin dual-channel-fd-mixin
))
37 (check-type mode boolean
"a boolean value")
38 (%set-fd-nonblock-mode
(fd-of fd-mixin
) mode
))
40 (defmethod output-fd-non-blocking ((fd-mixin dual-channel-fd-mixin
))
41 (%get-fd-nonblock-mode
(output-fd-of fd-mixin
)))
43 (defmethod (setf output-fd-non-blocking
) (mode (fd-mixin dual-channel-fd-mixin
))
44 (check-type mode boolean
"a boolean value")
45 (%set-fd-nonblock-mode
(output-fd-of fd-mixin
) mode
))
47 (defmethod fd-non-blocking ((fd-mixin dual-channel-single-fd-mixin
))
48 (%get-fd-nonblock-mode
(fd-of fd-mixin
)))
50 (defmethod (setf fd-non-blocking
) (mode (fd-mixin dual-channel-single-fd-mixin
))
51 (check-type mode boolean
"a boolean value")
52 (%set-fd-nonblock-mode
(fd-of fd-mixin
) mode
))