Cosmetic changes.
[iolib.git] / io.streams / fd-mixin.lisp
blob9b85bb015648f1601cccc6f9ee06230cbb95a80b
1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Indent-tabs-mode: NIL -*-
2 ;;;
3 ;;; fd-mixin.lisp --- insert description here
4 ;;;
5 ;;; Copyright (C) 2006-2007, Stelian Ionescu <sionescu@common-lisp.net>
6 ;;;
7 ;;; This code is free software; you can redistribute it and/or
8 ;;; modify it under the terms of the version 2.1 of
9 ;;; the GNU Lesser General Public License as published by
10 ;;; the Free Software Foundation, as clarified by the
11 ;;; preamble found here:
12 ;;; http://opensource.franz.com/preamble.html
13 ;;;
14 ;;; This program is distributed in the hope that it will be useful,
15 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;;; GNU General Public License for more details.
18 ;;;
19 ;;; You should have received a copy of the GNU Lesser General
20 ;;; Public License along with this library; if not, write to the
21 ;;; Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
22 ;;; Boston, MA 02110-1301, USA
24 (in-package :io.streams)
26 ;;;; Get and Set O_NONBLOCK
28 (defun %get-fd-nonblock-mode (fd)
29 (let ((current-flags (nix:fcntl fd nix:f-getfl)))
30 (logtest nix:o-nonblock current-flags)))
32 (defun %set-fd-nonblock-mode (fd mode)
33 (let* ((current-flags (nix:fcntl fd nix:f-getfl))
34 (new-flags (if mode
35 (logior current-flags nix:o-nonblock)
36 (logandc2 current-flags nix:o-nonblock))))
37 (when (/= new-flags current-flags)
38 (nix:fcntl fd nix:f-setfl new-flags))
39 (values mode)))
41 (defmethod input-fd-non-blocking ((fd-mixin dual-channel-fd-mixin))
42 (%get-fd-nonblock-mode (fd-of fd-mixin)))
44 (defmethod (setf input-fd-non-blocking) (mode (fd-mixin dual-channel-fd-mixin))
45 (check-type mode boolean "a boolean value")
46 (%set-fd-nonblock-mode (fd-of fd-mixin) mode))
48 (defmethod output-fd-non-blocking ((fd-mixin dual-channel-fd-mixin))
49 (%get-fd-nonblock-mode (output-fd-of fd-mixin)))
51 (defmethod (setf output-fd-non-blocking) (mode (fd-mixin dual-channel-fd-mixin))
52 (check-type mode boolean "a boolean value")
53 (%set-fd-nonblock-mode (output-fd-of fd-mixin) mode))
55 (defmethod fd-non-blocking ((fd-mixin dual-channel-single-fd-mixin))
56 (%get-fd-nonblock-mode (fd-of fd-mixin)))
58 (defmethod (setf fd-non-blocking) (mode (fd-mixin dual-channel-single-fd-mixin))
59 (check-type mode boolean "a boolean value")
60 (%set-fd-nonblock-mode (fd-of fd-mixin) mode))