1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
(* $Id: server.ml 182 2004-05-25 16:49:11Z gerd $
* ----------------------------------------------------------------------
*
*)
open Rtypes
open Xdr
open Rpc
open Rpc_server
open Sample_aux
let server_port = ref 0;;
(* this variable will contain the Internet port where this server is
* listening
*)
(***** Implementation of the procedures *****)
let plus1 session n reply =
reply (n+1)
;;
(***** Building a server *****)
let main() =
let esys = Unixqueue.create_unix_event_system() in
let server =
Sample_srv.P.V1.create_async_server
~proc_plus1: plus1
Rpc_server.Portmapped (* register with the portmapper *)
Tcp
Socket
esys
in
(* Set signal handler. Signals are the only way to stop the server;
* the default behaviour does not clean up the server, so we define
* appropriate handlers.
* Clean-up to do is mostly unregistering the program with the portmapper.
*)
List.iter
(fun signal ->
Sys.set_signal
signal
(Sys.Signal_handle (fun _ -> Rpc_server.stop_server server)))
[ Sys.sighup; Sys.sigint; Sys.sigquit; Sys.sigterm ];
(* Initialize the 'server_port' variable *)
server_port := Rpc_portmapper.port_of_program
Sample_aux.program_P'V1 "localhost" Tcp;
(* Now start serving *)
Unixqueue.run esys
;;
(***** running the server *****)
main();;
|