[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Nonblocking get-bytevector-n bug?
From: |
Amirouche Boubekki |
Subject: |
Re: Nonblocking get-bytevector-n bug? |
Date: |
Mon, 07 Dec 2015 13:44:11 +0100 |
User-agent: |
Roundcube Webmail/1.1.2 |
Le 2015-12-06 21:38, Marko Rauhamaa a écrit :
Guile 2.0.11 provides:
get-bytevector-n
get-bytevector-n!
get-bytevector-some
Of these, only get-bytevector-some seems to behave as expected when the
port is nonblocking:
First thanks for pointing the correct way to setup a non-blocking port.
I was missing that bit in my code.
I can't make work `get-bytevector-some` with my code. It only returns a
single cell bv.
Instead I use `char-ready?`. Here is the definition of `recv-some`:
```
(define (recv-some port)
(let next ((out '()))
(if (char-ready? port)
(let ((byte (get-u8 port)))
(if (eof-object? byte)
(u8-list->bytevector (reverse out))
(next (cons byte out))))
(u8-list->bytevector (reverse out)))))
```
FWIW, i also have a send-all procedure that works around the fact that
the socket is non blocking:
```
(define (send-all socket message cc)
(let loop ((message message))
(let* ((count (send socket message))
(message (bytevector-drop message count)))
(if (eq? (bytevector-length message) 0)
(cc)
(loop-add-writer socket (lambda () (loop message)))))))
```
`loop-add-writer` register a thunk to be run when the socket is ready
for writes.
I attached tests files.
async.scm
Description: Text document
client.scm
Description: Text document
server.scm
Description: Text document
Re: Nonblocking get-bytevector-n bug?,
Amirouche Boubekki <=
Re: Nonblocking get-bytevector-n bug?, Mark H Weaver, 2015/12/08