blob: 1e8260960f793913e397f4ce16a175ee0db8e383 [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
David Reiss0c90f6f2008-02-06 22:18:40 +000014 Some s -> Unix.shutdown s Unix.SHUTDOWN_ALL; Unix.close s;
iproctore470aa32007-08-10 20:48:12 +000015 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