blob: ac98b087b57f5844e6afe600123150742f6da0aa [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
14 Some s -> Unix.shutdown s Unix.SHUTDOWN_ALL; Unix.close s; sock <- None
15 | _ -> ()
16 method acceptImpl =
17 match sock with
18 Some s -> let (fd,_) = Unix.accept s in
19 new TChannelTransport.t (Unix.in_channel_of_descr fd,Unix.out_channel_of_descr fd)
20 | _ -> Transport.raise_TTransportExn "ServerSocket: Not listening but tried to accept" Transport.NOT_OPEN
21end