* [Caml-list] TIME-OUT
@ 2003-02-19 9:08 altavillasalvatore
2003-02-19 12:18 ` Michal Moskal
2003-02-19 12:34 ` Gerd Stolpmann
0 siblings, 2 replies; 4+ messages in thread
From: altavillasalvatore @ 2003-02-19 9:08 UTC (permalink / raw)
To: caml-list
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.
Regards.
-------------------
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] TIME-OUT
2003-02-19 9:08 [Caml-list] TIME-OUT altavillasalvatore
@ 2003-02-19 12:18 ` Michal Moskal
2003-02-19 12:34 ` Gerd Stolpmann
1 sibling, 0 replies; 4+ messages in thread
From: Michal Moskal @ 2003-02-19 12:18 UTC (permalink / raw)
To: altavillasalvatore; +Cc: caml-list
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] TIME-OUT
2003-02-19 9:08 [Caml-list] TIME-OUT altavillasalvatore
2003-02-19 12:18 ` Michal Moskal
@ 2003-02-19 12:34 ` Gerd Stolpmann
1 sibling, 0 replies; 4+ messages in thread
From: Gerd Stolpmann @ 2003-02-19 12:34 UTC (permalink / raw)
To: altavillasalvatore; +Cc: caml-list
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: [Caml-list] TIME-OUT
@ 2003-02-19 12:23 Beck01, Wolfgang
0 siblings, 0 replies; 4+ messages in thread
From: Beck01, Wolfgang @ 2003-02-19 12:23 UTC (permalink / raw)
To: altavillasalvatore, caml-list
altavillasalvatore@libero.it wrote
> I would want to introduce a Timeout for input operations (a floating-point value
> representing a time in seconds) of 15 second.
use 'select':
let rd_ready, wr_ready, exc_ready = select [sock] [][] 15.0
in
match rd_ready with
h :: _ ->
Unix.recvfrom h !buf 0 max []
| [] -> (* handle timeout *)
'select' on Windows is restricted to sockets, on Unix you can
use any file_descr.
--
Wolfgang Beck
T-Systems Nova GmbH
-------------------
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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2003-02-19 12:45 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-02-19 9:08 [Caml-list] TIME-OUT altavillasalvatore
2003-02-19 12:18 ` Michal Moskal
2003-02-19 12:34 ` Gerd Stolpmann
2003-02-19 12:23 Beck01, Wolfgang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox