From: Gerd Stolpmann <info@gerd-stolpmann.de>
To: "altavillasalvatore@libero.it" <altavillasalvatore@libero.it>
Cc: caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] TIME-OUT
Date: 19 Feb 2003 13:34:13 +0100 [thread overview]
Message-ID: <1045658053.18138.6.camel@hera> (raw)
In-Reply-To: <HAJTEF$4AA8E84016371F45884FD7602560746C@libero.it>
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
next prev parent reply other threads:[~2003-02-19 12:34 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-02-19 9:08 altavillasalvatore
2003-02-19 12:18 ` Michal Moskal
2003-02-19 12:34 ` Gerd Stolpmann [this message]
2003-02-19 12:23 Beck01, Wolfgang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1045658053.18138.6.camel@hera \
--to=info@gerd-stolpmann.de \
--cc=altavillasalvatore@libero.it \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox