r1293@opsdev009 (orig r69993): cpiro | 2007-11-14 22:26:26 -0800
[amiethrift.git] / lib / erl / src / transport / tTransport.erl
bloba7293be6ca97cb28cbe1ce3f52a3807487ec3f5d
1 %%% Copyright (c) 2007- Facebook
2 %%% Distributed under the Thrift Software License
3 %%%
4 %%% See accompanying file LICENSE or visit the Thrift site at:
5 %%% http://developers.facebook.com/thrift/
7 -module(tTransport).
9 -include("oop.hrl").
11 -include("thrift.hrl").
12 -include("transport/tTransport.hrl").
14 -behavior(oop).
16 -export([attr/4, super/0, inspect/1]).
18 -export([new/0, isOpen/1, open/1, close/1, read/2, readAll/2, effectful_write/2, effectful_flush/1]).
20 %%%
21 %%% define attributes
22 %%% 'super' is required unless ?MODULE is a base class
23 %%%
25 ?ATTR_DUMMY.
27 %%%
28 %%% behavior callbacks
29 %%%
31 %%% super() -> SuperModule = atom()
32 %%% | none
34 super() ->
35 none.
37 %%% inspect(This) -> string()
39 inspect(_This) ->
40 "".
42 %%%
43 %%% class methods
44 %%%
46 new() ->
47 #?MODULE{}.
49 %%%
50 %%% instance methods
51 %%%
53 e() ->
54 exit('tTransport is abstract').
56 isOpen(_This) -> e(), nil.
57 open(_This) -> e(), nil.
58 close(_This) -> e(), nil.
59 read(_This, _Sz) -> e(), nil.
61 readAll(This, Sz) ->
62 readAll_loop(This, Sz, "", 0).
64 readAll_loop(This, Sz, Buff, Have) ->
65 if
66 Have < Sz ->
67 Chunk = ?L1(read, Sz - Have),
69 %% man gen_tcp:
70 %% exactly Length bytes are returned, or an error;
71 %% possibly discarding less than Length bytes of data when
72 %% the socket gets closed from the other side.
74 %% error_logger:info_msg("READ |~p|", [Chunk]),
76 Have1 = Have + (Sz-Have), % length(Chunk)
77 Buff1 = Buff ++ Chunk, % TODO: ++ efficiency?
78 readAll_loop(This, Sz, Buff1, Have1);
79 true ->
80 Buff
81 end.
83 effectful_write(This, _Buf) ->
84 e(),
85 {nil, This}.
87 effectful_flush(This) ->
88 {nil, This}.