1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Indent-tabs-mode: NIL -*-
3 ;;; fd-mixin.lisp --- insert description here
5 ;;; Copyright (C) 2006-2007, Stelian Ionescu <sionescu@common-lisp.net>
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
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.
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
30 (defun %get-fd-nonblock-mode
(fd)
32 (error "nonblock stuff not implemented on windows yet"))
33 (defun %set-fd-nonblock-mode
(fd mode
)
34 (declare (ignore fd mode
))
35 (error "nonblock stuff not implemented on windows yet")))
38 (defun %get-fd-nonblock-mode
(fd)
39 (let ((current-flags (nix:fcntl fd nix
::f-getfl
)))
40 (logtest nix
::o-nonblock current-flags
)))
43 (defun %set-fd-nonblock-mode
(fd mode
)
44 (let* ((current-flags (nix:fcntl fd nix
::f-getfl
))
46 (logior current-flags nix
::o-nonblock
)
47 (logandc2 current-flags nix
::o-nonblock
))))
48 (when (/= new-flags current-flags
)
49 (nix:fcntl fd nix
::f-setfl new-flags
))
52 (defmethod input-fd-non-blocking ((fd-mixin dual-channel-fd-mixin
))
53 (%get-fd-nonblock-mode
(fd-of fd-mixin
)))
55 (defmethod (setf input-fd-non-blocking
) (mode (fd-mixin dual-channel-fd-mixin
))
56 (check-type mode boolean
"a boolean value")
57 (%set-fd-nonblock-mode
(fd-of fd-mixin
) mode
))
59 (defmethod output-fd-non-blocking ((fd-mixin dual-channel-fd-mixin
))
60 (%get-fd-nonblock-mode
(output-fd-of fd-mixin
)))
62 (defmethod (setf output-fd-non-blocking
) (mode (fd-mixin dual-channel-fd-mixin
))
63 (check-type mode boolean
"a boolean value")
64 (%set-fd-nonblock-mode
(output-fd-of fd-mixin
) mode
))
66 (defmethod fd-non-blocking ((fd-mixin dual-channel-single-fd-mixin
))
67 (%get-fd-nonblock-mode
(fd-of fd-mixin
)))
69 (defmethod (setf fd-non-blocking
) (mode (fd-mixin dual-channel-single-fd-mixin
))
70 (check-type mode boolean
"a boolean value")
71 (%set-fd-nonblock-mode
(fd-of fd-mixin
) mode
))