How are you doing Marco?

I'm looking at usocket-0.8.4. It may be worth exploring some of these aspects I see in its code:
1. option.lisp allows: (setf (socket-option mysocket :receive-timeout) ...)
2. usocket.lisp defines a generic socket-receive. It's only implemented for UDP sockets but I don't see why it shouldn't be implementable for stream-sockets too.

Otherwise I don't see a better solution in usocket than inefficiently checking for and reading a byte at a time, like this.

(defun read-available-vector (vector socket &key (start 0) (end nil))
  "Reads whatever is presently available in SOCKET without hanging.
   SOCKET and VECTOR are assumed to have elts of type (unsigned-byte 8).
   Returns first unwritten position in VECTOR and whether at end-of-file."
  (when (null end) (setq end (length vector)))
  (assert (<= 0 start end (length vector)))
  (flet ((socket-readyp ()
           (wait-for-input socket :timeout 0 :ready-only t)))
    (do ((i start (1+ i)))
        ((or (>= i end) (not (socket-readyp)))
         (values i nil))
      (let ((b (read-byte (socket-stream stream) nil nil)))
        (unless b (return (values i t)))
        (setf (aref vector i) b)))))

--
Vibhu

Reply via email to