From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id NAA00586; Wed, 19 Feb 2003 13:34:18 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id NAA00879 for ; Wed, 19 Feb 2003 13:34:17 +0100 (MET) Received: from mail.npc.de (fw.npc.de [62.225.140.214]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h1JCYHT15576 for ; Wed, 19 Feb 2003 13:34:17 +0100 (MET) Received: from p5080EC81.dip.t-dialin.net (lion.npc.de [192.168.129.1]) by mail.npc.de (Postfix) with ESMTP id 2B79B134B; Wed, 19 Feb 2003 13:34:16 +0100 (CET) Received: from hera.ffm.npc.de (hera.ffm.npc.de [192.168.130.8]) by p5080EC81.dip.t-dialin.net (Postfix STYX NPC GmbH) with ESMTP id A282678E0; Wed, 19 Feb 2003 13:34:14 +0100 (CET) Received: from ares.ffm.npc.de (ares.ffm.npc.de [192.168.130.32]) by hera.ffm.npc.de (Postfix HERA NPC GmbH) with ESMTP id 22958159B9; Wed, 19 Feb 2003 13:34:14 +0100 (CET) Received: from hera.ffm.npc.de (hera.ffm.npc.de [192.168.130.8]) by ares.ffm.npc.de (Postfix ARES NPC GmbH) with ESMTP id D1622A508; Wed, 19 Feb 2003 13:34:13 +0100 (CET) Subject: Re: [Caml-list] TIME-OUT From: Gerd Stolpmann To: "altavillasalvatore@libero.it" Cc: caml-list In-Reply-To: References: Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Mailer: Ximian Evolution 1.0.8 Date: 19 Feb 2003 13:34:13 +0100 Message-Id: <1045658053.18138.6.camel@hera> Mime-Version: 1.0 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Wed, 2003-02-19 at 10:08, altavillasalvatore@libero.it wrote: > Hi All, > > My problem is this: > > let risposta byte = > let pdu_length = String.length byte in > let my_name =Unix.gethostname() in > let my_entry_byname = Unix.gethostbyname my_name in > let my_addr = my_entry_byname.Unix.h_addr_list.(0) in > let sockaddr = Unix.ADDR_INET(my_addr, 161) in > let sock = Unix.socket Unix.PF_INET Unix.SOCK_DGRAM 0 in > let sock1 = Unix.ADDR_INET(my_addr, 12346) in > Unix.bind sock sock1; > let w = Unix.sendto sock byte 0 pdu_length [] sockaddr in > let max = 512 in > let buf=ref (String.create max) in > let len, addr =Unix.recvfrom sock !buf 0 max [] in > Unix.close sock; > let answer = String.sub !buf 0 len in > answer > > I would want to introduce a Timeout for input operations (a floating-point value representing a time in seconds) of 15 second. Unix.select is your friend. let rdlist,_,_ = Unix.select [sock] [] [] 15.0 in if rdlist = [] then raise Timeout; Otherwise, rdlist has one member: sock, and the socket has received a datagram. Gerd -- ------------------------------------------------------------ Gerd Stolpmann * Viktoriastr. 45 * 64293 Darmstadt * Germany gerd@gerd-stolpmann.de http://www.gerd-stolpmann.de ------------------------------------------------------------ ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners