| iproctor | 7897c92 | 2007-08-08 01:43:39 +0000 | [diff] [blame] | 1 | open Thrift | 
|  | 2 |  | 
|  | 3 | class t port = | 
|  | 4 | object | 
|  | 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 | 
| iproctor | e470aa3 | 2007-08-10 20:48:12 +0000 | [diff] [blame] | 14 | Some s -> Unix.shutdown s Unix.SHUTDOWN_ALL; Unix.close s; | 
|  | 15 | sock <- None | 
| iproctor | 7897c92 | 2007-08-08 01:43:39 +0000 | [diff] [blame] | 16 | | _ -> () | 
|  | 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) | 
| iproctor | e470aa3 | 2007-08-10 20:48:12 +0000 | [diff] [blame] | 21 | | _ -> raise (Transport.E (Transport.NOT_OPEN,"TServerSocket: Not listening but tried to accept")) | 
| iproctor | 7897c92 | 2007-08-08 01:43:39 +0000 | [diff] [blame] | 22 | end |