[Openmcl-devel] Transfer the contents of a file to a tcp stream

Christian Nybø chr at nybo.no
Fri May 13 00:58:14 PDT 2005


On May 5, 2005, at 22:55, Gary Byers wrote:
> Maybe something like:
>
> (let* ((bufsize 8192))
>   (ccl::%stack-block ((buf bufsize)
>                       (iovec (* 4 (ccl::record-length :iovec))))
>     ;; Set up each element of the iovec array to point at 1/4 of the
>     ;; buffer.
>     (dotimes (i 4)
>       (with-macptrs ((p (%inc-ptr iovec (* i (ccl::record-length 
> :iovec)))))
>         (setf (pref p :iovec.iov_base) (%inc-ptr buf (* i 2048))
>               (pref p :iovec.iov_len) 2048)))
>     ...
>     (loop
>       (let* ((nread (#_read file-fd buf bufsize)))
>         ((cond ((= nread bufsize)
>                 ;; Got a full buffer, write to socket via #_writev
>                 (#_writev socket-fd iovec 4))
>                ((> nread 0)
>                 ;; Got less than a full buffer.  Either adjust
>                 ;; the count of iovecs/the iov_len of the last one,
>                 ;; or just do a single #_write as before.
>                )
>                ((= nread 0) (return))
>                (t (error ...))))))))

I wrapped the writev that is called when (= nread bufsize) in a loop.  
It gets stuck quite often - the errno is -35, whose strerror is 
"Resource temporarily unavailable."
What should the program do when writev returns -35?
-- 
chr




More information about the Openmcl-devel mailing list