[plt-scheme] Re: ssl/tls connections

From: nik gaffney (nik at fo.am)
Date: Tue Mar 31 08:29:26 EDT 2009

Thanks for the reply, but the problem is that peek-byte, or peek-string
will commit the ssl connection to a read even if nothing is available to
be read. this blocks any write from the client.

So, I am wondering if there is a better way to combine the reading and
parsing which wont block writing.

> i'm a french IT student, so i don't know if my code will help you
> anyway.
> I didn't go far enough to implement secure negotiation but i managed
> to read from port directly with read-string.
> 
> ; recupServer: port -> string
> ; return the "first" block not null
> (define (recupServer->me port)
>     (let loop ()
>       (let ([available (peek-string TAILLEBLOCK 0 port)])
>         (if (null? available)
>             (loop)
>             (read-string TAILLEBLOCK port)))))
> 
> 
> 
> On 29 mar, 17:08, nik gaffney <n... at fo.am> wrote:
>> 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
>> server.
>>
>> (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))
>>         (begin
>>           (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.