blob: 9e797060d2acd180cc1403865a2f450b62d44e8d [file] [log] [blame]
iproctor7897c922007-08-08 01:43:39 +00001open Thrift
2
3class t port =
4object
5 inherit Transport.server_t
6 val mutable sock = None
7 method listen =
8 let s = Unix.socket Unix.PF_INET Unix.SOCK_STREAM 0 in
9 sock <- Some s;
10 Unix.bind s (Unix.ADDR_INET (Unix.inet_addr_any, port));
11 Unix.listen s 256
12 method close =
13 match sock with
iproctore470aa32007-08-10 20:48:12 +000014 Some s -> Unix.shutdown s Unix.SHUTDOWN_ALL; Unix.close s;
15 sock <- None
iproctor7897c922007-08-08 01:43:39 +000016 | _ -> ()
17 method acceptImpl =
18 match sock with
19 Some s -> let (fd,_) = Unix.accept s in
20 new TChannelTransport.t (Unix.in_channel_of_descr fd,Unix.out_channel_of_descr fd)
iproctore470aa32007-08-10 20:48:12 +000021 | _ -> raise (Transport.E (Transport.NOT_OPEN,"TServerSocket: Not listening but tried to accept"))
iproctor7897c922007-08-08 01:43:39 +000022end