[cl-plus-ssl-devel] Two LISTEN bugs

Ron Garret ron at flownet.com
Wed May 12 06:19:17 UTC 2010


On May 11, 2010, at 5:51 PM, Anton Vodonosov wrote:

> Hello Ron,
> 
> I revewed the patch, but didn't commited it, because was unable to test it yet. I am on Windows and CL+SSL doesn't support nonblocking IO here (there is no implementation for install-nonblock-flag for any Windows lisp). Therefore SSL-READ always blocks.
> 
> I will test it on Linux soon and then commit (I also have intention to handle errors in a separate nonblocking-ssl-funcall function, as David suggested).
> 
> Best regards,
> - Anton
> 

Here's an updated version that does buffered input.  Oddly, though, it does not actually seem to improve performance in my tests.

(defclass ssl-stream
    (fundamental-binary-input-stream
     fundamental-binary-output-stream 
     trivial-gray-stream-mixin)
  ((ssl-stream-socket
    :initarg :socket
    :accessor ssl-stream-socket)
   (close-callback
    :initarg :close-callback
    :accessor ssl-close-callback)
   (handle
    :initform nil
    :accessor ssl-stream-handle)
   (deadline
    :initform nil
    :initarg :deadline
    :accessor ssl-stream-deadline)
   (output-buffer
    :initform (make-buffer +initial-buffer-size+)
    :accessor ssl-stream-output-buffer)
   (output-pointer
    :initform 0
    :accessor ssl-stream-output-pointer)
   (input-buffer
    :initform (make-buffer +initial-buffer-size+)
    :accessor ssl-stream-input-buffer)
   (input-buffer-fill-ptr :initform 0 :accessor ssl-stream-input-buffer-fill-ptr)
   (input-buffer-curr-ptr :initform 0 :accessor ssl-stream-input-buffer-curr-ptr)
   (peeked-byte
    :initform nil
    :accessor ssl-stream-peeked-byte)))

(defun %stream-read-byte (s block)
  (or (prog1 (ssl-stream-peeked-byte s) (setf (ssl-stream-peeked-byte s) nil))
      (let ((buf (ssl-stream-input-buffer s)))
        (symbol-macrolet ((fill (ssl-stream-input-buffer-fill-ptr s))
                          (curr (ssl-stream-input-buffer-curr-ptr s)))
          (if (< curr fill)
            (prog1 (elt buf curr) (incf curr))
            (progn
              (setf curr 0)
              (with-pointer-to-vector-data (ptr buf)
                (setf fill (ssl-read (ssl-stream-handle s) ptr (length buf))))
              (cond ((and (< fill 0) block)
                     (input-wait s  (ssl-get-fd (ssl-stream-handle s)) nil)
                     (%stream-read-byte s block))
                    ((< fill 0) nil)
                    ((= fill 0) :eof)
                    (t (incf curr) (buffer-elt buf 0)))))))))

(defmethod stream-read-byte ((s ssl-stream)) (%stream-read-byte s t))

(defmethod stream-listen ((s ssl-stream))
  (or (ssl-stream-peeked-byte s)
      (setf (ssl-stream-peeked-byte s)
            (%stream-read-byte s nil))))





More information about the cl-plus-ssl-devel mailing list