[plt-scheme] ssl/tls connections

From: nik gaffney (nik at fo.am)
Date: Sun Mar 29 11:08:36 EDT 2009

Im working on a basic implementation of the xmpp/jabber protocol, and
having some trouble dealing with tls and sasl negotiation. I have a
working plaintext version, using tcp-connect, but changing to
ssl-connect has revealed some underlying problems.

The current approach involves using ssax to convert a string read from
the tcp stream. for some reason, read-line and read-char both hang when
reading from ejabberd, so im using read-byte.

Since byte-ready? is #f after a stanza has been sent, the following
function can be used to successfully parse individual responses from the

(parse-xmpp-response (bytes->string/utf-8 (read-async in)))
(define (read-async in)
  (define bstr (make-bytes 0 0))
  (when (byte-ready? in)
    (if (eq? (peek-byte in) eof)
        (break-thread (current-thread))
          (set! bstr (bytes-append bstr
                                   (make-bytes 1 (read-byte in))
                                   (read-async in)))))) bstr)

Unfortunately, this causes problems with ssl-connect (as described in
the openssl docs) as the ssl session is committed to a read by
byte-ready? thus writes are blocked until the server sends data.

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.


Posted on the users mailing list.