Permalink
Browse files

Reorganisation

  • Loading branch information...
1 parent 3ee5b17 commit 377cf1fcfcfc0a6ace38118eb78b80806c066e4d @SylvainGBR committed Jun 11, 2012
Showing with 76 additions and 68 deletions.
  1. +1 −1 Makefile
  2. +46 −0 actorsGlobal.ml
  3. +18 −0 actors.ml → actorsType.ml
  4. +5 −64 actorssg.ml
  5. +2 −1 client.ml
  6. +3 −1 server.ml
  7. +1 −1 test.ml
View
@@ -1,4 +1,4 @@
-SOURCES = my_queue.ml actors.ml actorssg.ml
+SOURCES = my_queue.ml actorsType.ml actorsGlobal.ml actorssg.ml
EXEC1 = client
EXEC2 = server
CAMLC = ocamlc
View
@@ -0,0 +1,46 @@
+open ActorsType
+
+let debug_flag = ref false
+let debug fmt =
+ if !debug_flag then Printf.eprintf fmt
+ else Printf.ifprintf stderr fmt;;
+
+let mutex_debug_flag = ref false
+let mutex_debug fmt =
+ if !mutex_debug_flag then Printf.eprintf fmt
+ else Printf.ifprintf stderr fmt;;
+
+Random.init (int_of_float (Unix.time()));;
+let local_node = Random.int 1024;;
+let local_machine = Unix.gethostname();;
+
+let (actors: (int, actor_env) Hashtbl.t) = Hashtbl.create 1313 (* Should probably be a weak hashtbl *)
+
+let actors_display() =
+ Printf.printf "Actors : ";
+ let f a b c = Printf.printf "%n\n%!" a; c in
+ Hashtbl.fold f actors ();;
+
+let (nodes : (int, node) Hashtbl.t) = Hashtbl.create 97
+let n_mutex = Mutex.create()
+
+let nodes_display() =
+ Printf.printf "Nodes : ";
+ let f a b c = Printf.printf "%n\n%!" a; c in
+ Hashtbl.fold f nodes ();;
+
+let mutex_lock mut =
+ mutex_debug "Locking. %!";
+ Mutex.lock mut;
+ mutex_debug "Locked. %!";;
+
+let mutex_unlock mut =
+ mutex_debug "Unlocking. %!";
+ Mutex.unlock mut;
+ mutex_debug "Unlocked. \n%!";;
+
+let actors_id = ref 0
+let a_mutex = Mutex.create()
+
+let (receive_scheduler : (actor * (message -> unit)) Queue.t) = Queue.create()
+let rs_mutex = Mutex.create()
@@ -43,6 +43,24 @@ and actor = {
actor_location : location;
}
+type actor_env = {actor: actor; sleeping : (message -> unit) Queue.t}
+
+type node = {
+ name : int;
+ agent : actor;
+ support : Thread.t;
+}
+
+type netdata = {
+ to_actor : int;
+ msg : message;
+}
+
+exception React of (message -> unit);;
+
+exception IncorrectMessage;;
+
+
let print_actor a =
match a.actor_location with
| Local lac -> Printf.printf "Local %n; \n%!" a.actor_id;
View
@@ -1,58 +1,5 @@
-open Actors
-
-let debug_flag = ref false
-let debug fmt =
- if !debug_flag then Printf.eprintf fmt
- else Printf.ifprintf stderr fmt;;
-
-let mutex_debug_flag = ref false
-let mutex_debug fmt =
- if !mutex_debug_flag then Printf.eprintf fmt
- else Printf.ifprintf stderr fmt;;
-
-Random.init (int_of_float (Unix.time()));;
-let local_node = Random.int 1024;;
-let local_machine = Unix.gethostname();;
-
-type actor_env = {actor: actor; sleeping : (message -> unit) Queue.t}
-
-let actors = Hashtbl.create 1313 (* Should probably be a weak hashtbl *)
-
-let actors_display() =
- Printf.printf "Actors : ";
- let f a b c = Printf.printf "%n\n%!" a; c in
- Hashtbl.fold f actors ();;
-
-type node = {
- name : int;
- agent : actor;
- support : Thread.t;
-}
-let nodes = Hashtbl.create 97
-let n_mutex = Mutex.create()
-
-let nodes_display() =
- Printf.printf "Nodes : ";
- let f a b c = Printf.printf "%n\n%!" a; c in
- Hashtbl.fold f nodes ();;
-
-exception IncorrectMessage;;
-
-let mutex_lock mut =
- mutex_debug "Locking. %!";
- Mutex.lock mut;
- mutex_debug "Locked. %!";;
-
-let mutex_unlock mut =
- mutex_debug "Unlocking. %!";
- Mutex.unlock mut;
- mutex_debug "Unlocked. \n%!";;
-
-let actors_id = ref 0
-let a_mutex = Mutex.create()
-
-let receive_scheduler = Queue.create()
-let rs_mutex = Mutex.create()
+open ActorsType
+open ActorsGlobal
let schedule_receive a f =
debug "In Schedule_receive : %!";
@@ -74,13 +21,6 @@ let awake aid =
end
| Remote o -> failwith "You cannot awake a remote actor";;
-type netdata = {
- to_actor : int;
- msg : message;
-}
-
-exception React of (message -> unit);;
-
let react f = raise (React f);;
exception NotHandled;;
@@ -174,6 +114,7 @@ and client_aux server_name =
with Not_found ->
prerr_endline (server_name ^ ": Host not found");
exit 2 in
+ Printf.printf "Adress : %s\n%!" (Unix.string_of_inet_addr server_addr);
Unix.open_connection (Unix.ADDR_INET(server_addr, port_number))
and client server_name =
let (i, o) = Unix.handle_unix_error client_aux server_name in
@@ -183,9 +124,9 @@ and client server_name =
let ac = create() in
let t = Thread.create receive_remote (i, rmn) in
let hst = {name = rmn; agent = ac; support = t} in
- (* mutex_lock n_mutex; *)
+ mutex_lock n_mutex;
Hashtbl.add nodes rmn hst;
- (* mutex_unlock n_mutex; *)
+ mutex_unlock n_mutex;
start ac (fun() -> sender o);
hst;;
View
@@ -1,6 +1,7 @@
open Sys;;
open Unix;;
-open Actors;;
+open ActorsType;;
+open ActorsGlobal;;
open Actorssg;;
Printf.printf "Local Node : %n\n%!" local_node;
View
@@ -1,6 +1,7 @@
open Sys;;
open Unix;;
-open Actors;;
+open ActorsType;;
+open ActorsGlobal;;
open Actorssg;;
let rec bonjour q =
@@ -52,6 +53,7 @@ let server () =
(* local_node := (!local_node) ^ string_of_int (Random.int 1024); *)
Printf.printf "Local Node : %n\n%!" local_node;
let port = 4242 in
+ Printf.printf "%s\n%!" (string_of_inet_addr ((gethostbyname(gethostname())).h_addr_list.(0)));
(* let host = (gethostbyname(gethostname())).h_addr_list.(0) in *)
(* let host = (gethostbyname "127.0.0.1").h_addr_list.(0) in *)
let host = (gethostbyname "193.55.250.242").h_addr_list.(0) in
View
@@ -1,4 +1,4 @@
-open Actors
+open ActorsType
open Actorssg
let ping_pong() =

0 comments on commit 377cf1f

Please sign in to comment.