Style changes.
[iolib/alendvai.git] / io.streams / gray / fd-mixin.lisp
blob61ae49027b0036627b5f384a4ec6be9f17a0ca6f
1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; indent-tabs-mode: nil -*-
2 ;;;
3 ;;; --- FD mixin definitions
4 ;;;
6 (in-package :io.streams)
8 ;;;; Get and Set O_NONBLOCK
10 (defun %get-fd-nonblock-mode (fd)
11 (let ((current-flags (nix:fcntl fd nix:f-getfl)))
12 (logtest nix:o-nonblock current-flags)))
14 (defun %set-fd-nonblock-mode (fd mode)
15 (let* ((current-flags (nix:fcntl fd nix:f-getfl))
16 (new-flags (if mode
17 (logior current-flags nix:o-nonblock)
18 (logandc2 current-flags nix:o-nonblock))))
19 (when (/= new-flags current-flags)
20 (nix:fcntl fd nix:f-setfl new-flags))
21 (values mode)))
23 (defmethod input-fd-non-blocking ((fd-mixin dual-channel-fd-mixin))
24 (%get-fd-nonblock-mode (fd-of fd-mixin)))
26 (defmethod (setf input-fd-non-blocking) (mode (fd-mixin dual-channel-fd-mixin))
27 (check-type mode boolean "a boolean value")
28 (%set-fd-nonblock-mode (fd-of fd-mixin) mode))
30 (defmethod output-fd-non-blocking ((fd-mixin dual-channel-fd-mixin))
31 (%get-fd-nonblock-mode (output-fd-of fd-mixin)))
33 (defmethod (setf output-fd-non-blocking) (mode (fd-mixin dual-channel-fd-mixin))
34 (check-type mode boolean "a boolean value")
35 (%set-fd-nonblock-mode (output-fd-of fd-mixin) mode))
37 (defmethod fd-non-blocking ((fd-mixin dual-channel-single-fd-mixin))
38 (%get-fd-nonblock-mode (fd-of fd-mixin)))
40 (defmethod (setf fd-non-blocking) (mode (fd-mixin dual-channel-single-fd-mixin))
41 (check-type mode boolean "a boolean value")
42 (%set-fd-nonblock-mode (fd-of fd-mixin) mode))