blob: c02f1ebacb4a049e55a39544ab1bd2d1334e1e80 [file] [log] [blame]
iproctor9a41a0c2007-07-16 21:59:24 +00001open Thrift
2
3module T = Transport
4
5class t host port=
6object (self)
7 inherit T.t
8 val mutable chans = None
9 method isOpen = chans != None
10 method opn =
11 try
12 chans <- Some(Unix.open_connection (Unix.ADDR_INET ((Unix.inet_addr_of_string host),port)))
13 with _ ->
14 T.raise_TTransportExn
15 ("Could not connect to "^host^":"^(string_of_int port))
16 T.NOT_OPEN
17 method close = match chans with None -> () | Some(inc,_) -> (Unix.shutdown_connection inc; chans <- None)
18 method read buf off len = match chans with
19 None -> T.raise_TTransportExn "Socket not open" T.NOT_OPEN
20 | Some(i,o) ->
21 try
22 really_input i buf off len; len
23 with _ -> T.raise_TTransportExn ("TSocket: Could not read "^(string_of_int len)^" from "^host^":"^(string_of_int port)) T.UNKNOWN
24 method write buf off len = match chans with
25 None -> T.raise_TTransportExn "Socket not open" T.NOT_OPEN
26 | Some(i,o) -> output o buf off len
27 method flush = match chans with
28 None -> T.raise_TTransportExn "Socket not open" T.NOT_OPEN
29 | Some(i,o) -> flush o
30end
31
32