Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] OCaml-ssl and input_string
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: asmadeus77@g...
Subject: Re: [Caml-list] OCaml-ssl and input_string
Well, I don't know how it should work, but from what I've seen, it
seems that its read function will wait untill there is something to
read if nothing is available.

Anyway, I have written an input_line (read character by character
untill a '\n') function which allows me to stop as soon as I can match
the begining of the line read with a pattern I get on the greeting.
That will work untill someone tries to send me funny mails with lots
of line feeds followed by weird 8-10 characters strings followed by a
space, I guess it's safe enough.

I just don't feel confident writing things such as :

  let ret = Buffer.create 1024 in
  let str = ref (input_line s) in
  while try Scanf.sscanf !str (Scanf.format_from_string (id^ " ")  "")
(fun _ -> ()) (); false with _-> true do
    Buffer.add_string ret !str;
    str:=input_line s
  Buffer.contents ret

On 5/6/08, Berke Durak <> wrote:
> Hello,
> From what I've inferred from ocaml-ssl's documentation, its "read" function
> has Unix-like non-blocking
> semantics.
> This means that read returns the number of bytes available, not the number
> of bytes requested.
> Hence you need an extra buffering/parsing layer on top of SSL sockets.
> However you are using
> IMAP, which is line-oriented, I guess Ssl.input_string should do what you
> want.
> --
> Berke