1 ;;;; -*- Mode: Lisp; indent-tabs-mode: nil -*-
3 ;;; events.lisp --- io.multiplexer test suite.
5 ;;; Copyright (C) 2007, Luis Oliveira <loliveira@common-lisp.net>
7 ;;; Permission is hereby granted, free of charge, to any person
8 ;;; obtaining a copy of this software and associated documentation
9 ;;; files (the "Software"), to deal in the Software without
10 ;;; restriction, including without limitation the rights to use, copy,
11 ;;; modify, merge, publish, distribute, sublicense, and/or sell copies
12 ;;; of the Software, and to permit persons to whom the Software is
13 ;;; furnished to do so, subject to the following conditions:
15 ;;; The above copyright notice and this permission notice shall be
16 ;;; included in all copies or substantial portions of the Software.
18 ;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 ;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 ;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 ;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 ;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 ;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 ;;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 ;;; DEALINGS IN THE SOFTWARE.
27 (in-package #:iolib-tests
)
29 (defmacro with-event-base
/for-each-mux
((base &rest initargs
) &body body
)
31 (dolist (mux (mapcar #'cdr
*available-multiplexers
*) failed-list
)
33 (with-event-base (,base
:mux mux
,@initargs
)
36 (push (cons mux err
) failed-list
))))))
39 (with-event-base/for-each-mux
(base)
40 (event-dispatch base
:timeout
0))
44 (with-event-base/for-each-mux
(base)
46 (add-timeout base
(lambda (fd event
)
50 (event-dispatch base
:timeout
0)
55 (with-event-base/for-each-mux
(base)
57 (add-timeout base
(lambda (fd event
)
61 (event-dispatch base
:one-shot t
)
62 (assert (eq cb
:timeout
))))
65 ;;; regression test: timeouts' absolute times used used to be
66 ;;; incremented with the relative time ad infinitum.
68 (with-event-base/for-each-mux
(base)
70 (add-timeout base
(lambda (fd event
)
74 (event-dispatch base
:one-shot t
:timeout
2)
75 (assert (eq cb
:timeout
))))
78 (defun timeout-cb (fd event
)
79 (declare (ignore fd event
))
82 (defmacro waiting-for-event
((base fd event-type
) &body body
)
83 (with-unique-names (fd-arg event-arg
)
86 (add-fd ,base
,fd
,event-type
87 (lambda (,fd-arg
,event-arg
)
88 (when (eq ,event-arg
:error
)
89 (error "error with ~A" ,fd-arg
))
92 (event-dispatch ,base
:one-shot t
)))))
94 ;;; FIXME: doesn't work with SELECT.
95 (deftest event-base-with-sockets
96 (with-event-base (base :mux
'kqueue-multiplexer
)
97 (with-socket (passive :family
:ipv4
:connect
:passive
98 :local-host
+ipv4-unspecified
+)
99 (with-socket (active :family
:ipv4
:remote-port
(local-port passive
)
100 :remote-host
#(127 0 0 1))
101 (add-timeout base
#'timeout-cb
5)
103 (waiting-for-event (base (fd-of passive
) :read
)
104 (setq peer
(accept-connection passive
)))
105 (assert (socket-open-p peer
)))
106 ;; TODO: send and receive some stuff