Coverage report: /home/ellis/.stash/lisp/cl-plus-ssl/src/ssl-funcall.lisp
Kind | Covered | All | % |
expression | 7 | 82 | 8.5 |
branch | 0 | 4 | 0.0 |
Key
Not instrumented
Conditionalized out
Executed
Not executed
Both branches taken
One branch taken
Neither branch taken
1
;;;; -*- Mode: LISP; Syntax: COMMON-LISP; indent-tabs-mode: nil; coding: utf-8; show-trailing-whitespace: t -*-
3
;;; Copyright (C) contributors as per cl+ssl git history
5
;;; See LICENSE for details.
7
(eval-when (:compile-toplevel)
9
(optimize (speed 3) (space 1) (safety 1) (debug 0) (compilation-speed 0))))
14
(defmethod stream-deadline ((stream ccl::basic-stream))
15
(ccl::ioblock-deadline (ccl::stream-ioblock stream t)))
17
(defmethod stream-deadline ((stream t))
20
;;; Waiting for output to be possible
23
(defun milliseconds-until-deadline (deadline stream)
24
(let* ((now (get-internal-real-time)))
26
(error 'ccl::communication-deadline-expired :stream stream)
28
(round (- deadline now) (/ internal-time-units-per-second 1000))))))
31
(defun output-wait (stream fd deadline)
33
(setf deadline (stream-deadline (ssl-stream-socket stream))))
36
(milliseconds-until-deadline deadline stream)
38
(multiple-value-bind (win timedout error)
39
(ccl::process-output-wait fd timeout)
42
(error 'ccl::communication-deadline-expired :stream stream)
43
(ccl::stream-io-error stream (- error) "write"))))))
45
(defun seconds-until-deadline (deadline)
46
(/ (- deadline (get-internal-real-time))
47
internal-time-units-per-second))
50
(defun output-wait (stream fd deadline)
51
(declare (ignore stream))
53
;; *deadline* is handled by wait-until-fd-usable automatically,
54
;; but we need to turn a user-specified deadline into a timeout
56
(seconds-until-deadline deadline))))
57
(sb-sys:wait-until-fd-usable fd :output timeout)))
60
(eval-when (:compile-top-level :load-top-level :execute)
64
(defun output-wait (stream fd deadline)
65
(declare (ignore stream))
68
(seconds-until-deadline deadline))))
69
(mp:process-wait-with-timeout "cl+ssl waiting for output"
74
#-(or clozure-common-lisp sbcl allegro)
75
(defun output-wait (stream fd deadline)
76
(declare (ignore stream fd deadline))
77
;; This situation means that the lisp set our fd to non-blocking mode,
78
;; and streams.lisp didn't know how to undo that.
79
(warn "cl+ssl::output-wait is not implemented for this lisp, but a non-blocking stream is encountered"))
82
;;; Waiting for input to be possible
85
(defun input-wait (stream fd deadline)
87
(setf deadline (stream-deadline (ssl-stream-socket stream))))
90
(milliseconds-until-deadline deadline stream)
92
(multiple-value-bind (win timedout error)
93
(ccl::process-input-wait fd timeout)
96
(error 'ccl::communication-deadline-expired :stream stream)
97
(ccl::stream-io-error stream (- error) "read"))))))
100
(defun input-wait (stream fd deadline)
101
(declare (ignore stream))
103
;; *deadline* is handled by wait-until-fd-usable automatically,
104
;; but we need to turn a user-specified deadline into a timeout
106
(seconds-until-deadline deadline))))
107
(sb-sys:wait-until-fd-usable fd :input timeout)))
110
(defun input-wait (stream fd deadline)
111
(declare (ignore stream))
114
(max 0 (seconds-until-deadline deadline)))))
115
(mp:wait-for-input-available fd
117
:whostate "cl+ssl waiting for input")))
120
(defun input-wait (stream fd deadline)
121
(declare (ignore fd))
125
(max 0 (seconds-until-deadline deadline)))))
126
(system:wait-for-input-streams (list (ssl-stream-socket stream))
128
:wait-reason "cl+ssl waiting for input")))
130
#-(or clozure-common-lisp sbcl allegro lispworks)
131
(defun input-wait (stream fd deadline)
132
(declare (ignore stream fd deadline))
133
;; This situation means that the lisp set our fd to non-blocking mode,
134
;; and streams.lisp didn't know how to undo that.
135
(warn "cl+ssl::input-wait is not implemented for this lisp, but a non-blocking stream is encountered"))
139
(declaim (inline ensure-ssl-funcall))
140
(defun ensure-ssl-funcall (stream success-test func handle &rest other-args)
143
(let ((*bio-socket* (ssl-stream-socket stream))) ;for Lisp-BIO callbacks
144
(apply func handle other-args))))
145
(when (funcall success-test ret)
147
(let ((error (ssl-get-error handle ret)))
149
(#.+ssl-error-want-read+
152
(ssl-stream-deadline stream)))
153
(#.+ssl-error-want-write+
156
(ssl-stream-deadline stream)))
158
(ssl-signal-error handle func error ret)))))))
160
(declaim (inline nonblocking-ssl-funcall))
161
(defun nonblocking-ssl-funcall (stream success-test func handle &rest other-args)
164
(let ((*bio-socket* (ssl-stream-socket stream))) ;for Lisp-BIO callbacks
165
(apply func handle other-args))))
166
(when (funcall success-test ret)
168
(let ((error (ssl-get-error handle ret)))
170
((#.+ssl-error-want-read+ #.+ssl-error-want-write+)
173
(ssl-signal-error handle func error ret)))))))