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 NAA00487; Wed, 19 Feb 2003 13:21:26 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id NAA00479 for ; Wed, 19 Feb 2003 13:21:25 +0100 (MET) Received: from ep09.kernel.pl (ep09.kernel.pl [212.87.11.162]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h1JCLOP13041 for ; Wed, 19 Feb 2003 13:21:25 +0100 (MET) Received: (qmail 23467 invoked by uid 566); 19 Feb 2003 12:21:23 -0000 Date: Wed, 19 Feb 2003 13:18:27 +0100 From: Michal Moskal To: "altavillasalvatore@libero.it" Cc: caml-list@inria.fr Subject: Re: [Caml-list] TIME-OUT Message-ID: <20030219121827.GA7939@roke.freak> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4i X-PGP-Fingerprint: CF89 1B14 11BE 1CC9 2CA3 7497 5E32 69B4 BC71 B4C2 X-AntiVirus: scanned for viruses by AMaViS 0.2.1 (http://amavis.org/) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Wed, Feb 19, 2003 at 10:08:39AM +0100, 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. Either use Unix.select (to wait 15 second until input is available) or Unix.alarm/Unix.setitimer (to arrange SIGALRM to be delivered in 15 seconds, so it will break recvfrom). First solution is probably cleaner and more efficient (and I'm not sure if recvfrom won't restart after signal being delivered). -- : Michal Moskal ::::: malekith/at/pld-linux.org : GCS {C,UL}++++$ a? !tv : PLD Linux ::::::: Wroclaw University, CS Dept : {E-,w}-- {b++,e}>+++ h ------------------- 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