Rev 30 | Blame | Compare with Previous | Last modification | View Log | RSS feed
(*Licensed to the Apache Software Foundation (ASF) under oneor more contributor license agreements. See the NOTICE filedistributed with this work for additional informationregarding copyright ownership. The ASF licenses this fileto you under the Apache License, Version 2.0 (the"License"); you may not use this file except in compliancewith the License. You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing,software distributed under the License is distributed on an"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANYKIND, either express or implied. See the License for thespecific language governing permissions and limitationsunder the License.*)open Thriftmodule T = Transportclass t host port=object (self)inherit T.tval mutable chans = Nonemethod isOpen = chans != Nonemethod opn =trylet addr = (let {Unix.h_addr_list=x} = Unix.gethostbyname host in x.(0)) inchans <- Some(Unix.open_connection (Unix.ADDR_INET (addr,port)))withUnix.Unix_error (e,fn,_) -> raise (T.E (T.NOT_OPEN, ("TSocket: Could not connect to "^host^":"^(string_of_int port)^" because: "^fn^":"^(Unix.error_message e))))| _ -> raise (T.E (T.NOT_OPEN, ("TSocket: Could not connect to "^host^":"^(string_of_int port))))method close =match chans withNone -> ()| Some(inc,out) -> (Unix.shutdown_connection inc;close_in inc;chans <- None)method read buf off len = match chans withNone -> raise (T.E (T.NOT_OPEN, "TSocket: Socket not open"))| Some(i,o) ->tryreally_input i buf off len; lenwithUnix.Unix_error (e,fn,_) -> raise (T.E (T.UNKNOWN, ("TSocket: Could not read "^(string_of_int len)^" from "^host^":"^(string_of_int port)^" because: "^fn^":"^(Unix.error_message e))))| _ -> raise (T.E (T.UNKNOWN, ("TSocket: Could not read "^(string_of_int len)^" from "^host^":"^(string_of_int port))))method write buf off len = match chans withNone -> raise (T.E (T.NOT_OPEN, "TSocket: Socket not open"))| Some(i,o) -> output o buf off lenmethod flush = match chans withNone -> raise (T.E (T.NOT_OPEN, "TSocket: Socket not open"))| Some(i,o) -> flush oend