From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=AWL,NO_REAL_NAME autolearn=disabled version=3.1.3 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 176C6BBCA for ; Mon, 5 May 2008 21:54:15 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AnoBAE8CH0jAXQImiGdsb2JhbACQe38BAQEPIJUthBQ X-IronPort-AV: E=Sophos;i="4.27,439,1204498800"; d="scan'208";a="25858681" Received: from discorde.inria.fr ([192.93.2.38]) by mail4-smtp-sop.national.inria.fr with ESMTP; 05 May 2008 21:54:14 +0200 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id m45JsE2q029309 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Mon, 5 May 2008 21:54:14 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AkcBALcCH0hA6bjnc2dsb2JhbACQe38BDAMEBAkPBZUrhBQ X-IronPort-AV: E=Sophos;i="4.27,439,1204498800"; d="scan'208";a="11872864" Received: from wr-out-0506.google.com ([64.233.184.231]) by mail1-smtp-roc.national.inria.fr with ESMTP; 05 May 2008 21:54:12 +0200 Received: by wr-out-0506.google.com with SMTP id c57so1238402wra.9 for ; Mon, 05 May 2008 12:54:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; bh=a9E2l4xyGCWWJ1LXYu35NK/WLISpeDrFvuqIduEOF1w=; b=jatG/puGFRz5bf37cj356Xqw6cbCPfFeIV9CrskqlhkYyTiAh9ClAtoGVdE7E7jXWsu3GNOtxcMdf/Qw9C+ASAFnmvQViMjtdTXW1VJpn4BtpgDgaU85kchorr7VNkIltdBwAHYwPbouz5k/U+SoZMaWlAt1tadQ7pUD8dK6WbU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=nGGfrKGs5UCgq8NB9Ce0o6STxI/w/O+fsUxVarFF3s1Jn7rVwf1RJaWYyBY/nBNf+YOdtgL6bSXFP6PiCIxaSF5qLIprssUBDOt6XDxSrWYfzfPOiDNKhQvd7CvJqm0Kb2FAaigqqXcFFC5wecsL0Xl1j9w8DigiPrmzGTgY0tM= Received: by 10.142.47.6 with SMTP id u6mr2672697wfu.111.1210017250640; Mon, 05 May 2008 12:54:10 -0700 (PDT) Received: by 10.143.174.3 with HTTP; Mon, 5 May 2008 12:54:10 -0700 (PDT) Message-ID: Date: Mon, 5 May 2008 21:54:10 +0200 From: asmadeus77@gmail.com To: caml-list Subject: [Caml-list] OCaml-ssl and input_string MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Miltered: at discorde with ID 481F65E6.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; sockets:01 buf:01 buf:01 initializing:01 toplevel:01 wildcards:01 chunks:01 martinet:01 regexp:01 pcre:01 1400:98 kbs:98 10.:98 unix:01 caml-list:01 Hello, I'm making a simple mail client for gmail using IMAP, and I need to use ssl sockets. So far so good, there's a library called ocaml-ssl which works quite well, untill you need to read what the server sends. At first, the function input_string in the library is defined by let input_string ssl = let bufsize = 1024 in let buf = String.create bufsize in let ret = ref "" in let r = ref 1 in while !r <> 0 do r := read ssl buf 0 bufsize; ret := !ret ^ (String.sub buf 0 !r) done; !ret Which doesn't work, since read will wait untill there is something to read if there is nothing waiting to be read, thus will never return 0. I've changed the loop condition to "while !r = bufsize", initializing r with bufsize, and I've been satisfied with the result during my early testing (discovering the IMAP protocol in toplevel) Now, though, I've encountered a problem - it seems that the function returns too early, meaning that there is still some text left to be read after it has been invoked. I've discovered that the size of the returned strings is quite often 1400 or 648, but it can be anything, and changing the variable "bufsize" doesn't help (I guess it's the size of the packets sent by the server, but couldn't the socket hold more characters ? There's usually been a couple of seconds between two input_string calls, so there should be more than just a couple of KBs) I've tried adding a poll - (same function with "let fdescr_of_ssl = file_descr_of_socket ssl in while Unix.select [fdescr_of_ssl] [] [] 10. <> [],[],[] do") - but the result, though better, isn't granteed unless I set the timeout to at least 5-10 seconds, and even there I've had cases of uncomplete returns, even though they were rare enough to bear with. Anyway, I've decided to program this mail client to avoid waiting for the slow gmail web view, so I'd like to not to use a select there : Is it possible to read the socket untill a known string, to be sure the request is done, without waiting after it ? (the string I need to match is "known_identifier_without_space OK Success\r\n" eventually leaving the "OK Success" as wildcards to check for (it could be "BAD why it is bad\r\n")) I can assume I'm not making two requests at once, thus being sure that I can read the socket by large chunks untill the end matches, but I would rather not do so if possible. Any clue ? Thanks, Dominique Martinet PS : A friend of mine is wondering if there's a regexp for ranges in the Str module (like "aaaa?" would be "a{3-4}" in pcre), I'm sure he'll be glad if someone could ensure him there isn't any :P