From: "Olivier Pérès" <olivier.peres@laposte.net>
To: caml-list@inria.fr
Subject: Re: [Caml-list] use of abstract type "inet_addr"
Date: Tue, 02 Mar 2004 11:00:44 +0100 [thread overview]
Message-ID: <40445B4C.9040708@laposte.net> (raw)
In-Reply-To: <20040302010059.48823.qmail@web41208.mail.yahoo.com>
Vasili Galchin wrote:
> I want to use type "inet_addr"
Here is some code I wrote for my fourth year project (due in June
this year, it is still far from complete). Its purpose is to allow
simple definition and parallel execution of processes, and it has to be
suitably easy for teaching high-level parallel programming without
losing time on low-level concerns. Those two functions -- translated to
English -- are among those used to connect processes using sockets (the
actual process is hidden from the user). The first one shows how to
build an inet_address and the second one shows how to turn it into a
sockaddr. They're a bit rough but work for now (not released yet).
By the way, if someone could tell me why I don't get the Not_found
exception when a host is not found (the program waits forever), I would
appreciate it.
(* this functions takes either an IPv4 dotted decimal address or
a host name, and returns an inet_addr. *)
let ia_of_string s =
try
(* if the user gave an IP address, use it *)
inet_addr_of_string s
with Failure _ ->
try
(* assume it is a host name and resolve it *)
(gethostbyname (s)).h_addr_list.(0)
with Not_found -> failwith ("Unknown host : "^s)
(* this fetches a "network" (type provided by my library)
that was set up on the given machine and the given port. *)
let get_network machine port =
(* build address machine:port *)
(* Net_remote is a constructor for type network *)
let net = Net_remote (ADDR_INET (ia_of_string machine, port)) in
(* ping the network to check it is actually here *)
(* net_ping is also provided by my library *)
if net_ping net
then
net
else
failwith "Remote network unreachable"
Olivier Pérès.
-------------------
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:[~2004-03-02 9:59 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-03-01 14:24 [Caml-list] The Makefile Rakotomandimby Mihamina
2004-03-01 16:04 ` Remi Vanicat
2004-03-01 16:41 ` Rakotomandimby Mihamina
2004-03-02 1:00 ` [Caml-list] use of abstract type "inet_addr" Vasili Galchin
2004-03-02 10:00 ` Olivier Pérès [this message]
2004-03-02 15:38 ` Christophe TROESTLER
2004-03-04 2:48 ` SooHyoung Oh
2004-03-04 15:53 ` Henri DF
2004-03-05 3:25 ` [Caml-list] Test case syntax error Vasili Galchin
2004-03-05 4:42 ` William Lovas
2004-03-05 7:39 ` Shawn Wagner
2004-03-05 8:05 ` sebastien FURIC
2004-03-05 12:44 ` John Carr
2004-03-05 15:13 ` Remi Vanicat
2004-03-05 18:00 ` [Caml-list] use of abstract type "inet_addr" Didier Remy
2004-03-01 16:37 ` [Caml-list] The Makefile Rakotomandimby Mihamina
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=40445B4C.9040708@laposte.net \
--to=olivier.peres@laposte.net \
--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