guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: uniform-array-read!


From: William Xu
Subject: Re: uniform-array-read!
Date: Fri, 03 Feb 2006 12:46:20 +0800
User-agent: Gnus/5.110004 (No Gnus v0.4) Emacs/22.0.50 (gnu/linux)

William Xu <address@hidden> writes:

> Alan Bram <address@hidden> writes:
>
> [...]
>
>> |
>> | (define read-network-byte
>> |   (lambda (port)
>> |     (let ((v (make-uniform-array #\nul 1)))
>                                           ^^^
> when array size is 1, it works. But if i set it to 3, for instance. Then
> it'll still block..
>
>> |       (uniform-array-read! v port)
>> |       (uniform-vector-ref v 0))))
>> `--
>
> And i made the following workaround, using `recv!'. At least it works as
> expected.
>
> (define (qq-read-binary-list sock length)
>   "Read at most LENGTH bytes from SOCK. Return a list of integers."
>   (let* ((buf (make-string length #\ ))
>        (count (recv! sock buf)))
>     (if (> count 0)                   ; we have read something.
>       (map
>        char->integer
>        (string->list (substring buf 0 count)))
>       lst)))

Oh, sorry. A minor mistake in the code. Here's updated, 

(define (qq-read-list sock length)
  "Read at most LENGTH bytes. Return a list of integers."
  (let* ((buf (make-string length #\ ))
         (count (recv! sock buf)))
    (if (> count 0)                     ; we have read something.
        (map
         char->integer
         (string->list (substring buf 0 count))))))

-- 
William




reply via email to

[Prev in Thread] Current Thread [Next in Thread]