[plt-scheme] ssl/tls connections
On Sun, Mar 29, 2009 at 4:08 PM, nik gaffney <nik at fo.am> wrote:
> So, I was wondering what other approaches to reading from a port would
> get around this problem, and/or if there are any examples anyone could
> point me to.
Try syncing on the input and output ports, rather than peeking. I
don't know for sure but I guess that sync is implemented in terms of
select, and the OpenSSL docs suggest you can use select to determine
if data is ready without committing to a read or a write.
I expect your funciton read-async below could be better written. Two things:
- I don't think using breaks is a great idea. Sync seems better.
- Continually calling bytes-append is going to give O(n^2)
complexity. Better to assemble a list of bytes, and then apply
bytes-append, for O(n) complexity.
(define (read-async in)
(define bstr (make-bytes 0 0))
(when (byte-ready? in)
(if (eq? (peek-byte in) eof)
(break-thread (current-thread))
(begin
(set! bstr (bytes-append bstr
(make-bytes 1 (read-byte in))
(read-async in)))))) bstr)
N.