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