hop-2012/ocamlmsg.ml

34 lines
893 B
OCaml
Raw Normal View History

2012-01-08 17:41:04 +00:00
open Unix
open Printf
open Thread
let rec accept_loop sock =
let (s, peername) = accept sock in
ignore (Relay.start_relay (s, peername));
accept_loop sock
let start_net port_number =
let sock = socket PF_INET SOCK_STREAM 0 in
setsockopt sock SO_REUSEADDR true;
bind sock (ADDR_INET (inet_addr_of_string "0.0.0.0", port_number));
listen sock 5;
2012-01-08 19:48:07 +00:00
Log.info "Accepting connections" [Sexp.Str (string_of_int port_number)];
2012-01-08 17:41:04 +00:00
accept_loop sock
2012-01-08 19:48:07 +00:00
let hook_log () =
let old_hook = !Log.hook in
let new_hook label body =
ignore (Node.post "system.log" (Sexp.Str label) body (Sexp.Str ""));
old_hook label body
in
Log.hook := new_hook
2012-01-08 17:41:04 +00:00
let _ =
printf "ocamlmsg ALPHA, Copyright (C) 2012 Tony Garnock-Jones. All rights reserved.\n%!";
2012-01-08 19:02:18 +00:00
Sys.set_signal Sys.sigpipe Sys.Signal_ignore;
2012-01-08 17:41:04 +00:00
Uuid.init ();
Factory.init ();
Queuenode.init ();
2012-01-08 19:48:07 +00:00
hook_log ();
2012-01-08 17:41:04 +00:00
start_net 5671