Marco,
 
If this works for you, great. I've always avoided these higher-level wrappings 
of sockets, and try to use as close to the BSD interface as I can (which made 
SBCL a very good fit for me). It could be worth looking to see if LW has 
recv(2) directly exposed somewhere.
 
Cheers,
Thomas

> Le 18/12/2025 11:39 CET, Marco Antoniotti <[email protected]> a 
> écrit :
>  
>  
> Thank you Vibhu
>  
> That is exactly what I came up with, and it seems to work decently well.  
> Only thing, I put a non-zero timeout.
>  
> All the best
>  
> Marco
> 
> On Thu, Dec 18, 2025 at 10:18 AM Vibhu Mohindra <[email protected] 
> mailto:[email protected]> wrote:
> 
> > -------- Forwarded Message --------
> > Subject: Re: READ-SEQUENCE and USOCKET
> > Date: Thu, 18 Dec 2025 10:14:57 +0100
> > From: Vibhu Mohindra <[email protected] 
> > mailto:[email protected]>
> > To: [email protected] mailto:[email protected]
> > 
> > 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
> > 
>  
> 
> --
> Marco Antoniotti, Professor, Director         tel. +39 - 02 64 48 79 01
> DISCo, University of Milan-Bicocca U14 2043   http://dcb.disco.unimib.it
> Viale Sarca 336
> I-20126 Milan (MI) ITALY
> 
> REGAINS: https://regains.disco.unimib.it/
> 

Reply via email to