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 |
| 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 |
| 21 | end |