%%% Copyright (c) 2007- Facebook
%%% Distributed under the Thrift Software License
-%%%
+%%%
%%% See accompanying file LICENSE or visit the Thrift site at:
%%% http://developers.facebook.com/thrift/
-export([attr/4, super/0, inspect/1]).
--export([new/1, isOpen/1, open/1, close/1, read/2, effectful_write/2, effectful_flush/1]).
+-export([new/1, isOpen/1, effectful_open/1, effectful_close/1, read/2, effectful_write/2, effectful_flush/1]).
%%%
%%% define attributes
?DEFINE_ATTR(super);
?DEFINE_ATTR(transport);
?DEFINE_ATTR(wbuf).
-
+
%%%
%%% behavior callbacks
%%%
-
+
%%% super() -> SuperModule = atom()
%%% | none
Transport = oop:get(This, transport),
?R0(Transport, isOpen).
-open(This) ->
+effectful_open(This) ->
Transport = oop:get(This, transport),
- ?R0(Transport, open).
+ ?R0(Transport, effectful_open),
+ {ok, This}.
-close(This) ->
+effectful_close(This) ->
Transport = oop:get(This, transport),
- ?R0(Transport, close).
+ ?R0(Transport, effectful_close),
+ {ok, This}.
read(This, Sz) ->
Transport = oop:get(This, transport),
effectful_flush(This) ->
Wbuf = oop:get(This, wbuf),
- Transport = oop:get(This, transport),
+ Transport = oop:get(This, transport),
?R1(Transport, effectful_write, Wbuf),
?R0(Transport, effectful_flush),
This1 = oop:set(This, wbuf, ""),
%%% Copyright (c) 2007- Facebook
%%% Distributed under the Thrift Software License
-%%%
+%%%
%%% See accompanying file LICENSE or visit the Thrift site at:
%%% http://developers.facebook.com/thrift/
-export([attr/4, super/0, inspect/1]).
--export([new/0, isOpen/1, open/1, close/1, read/2, readAll/2, effectful_write/2, effectful_flush/1]).
+-export([new/0, isOpen/1, effectful_open/1, effectful_close/1, read/2, readAll/2, effectful_write/2, effectful_flush/1]).
%%%
%%% define attributes
%%%
%%% behavior callbacks
%%%
-
+
%%% super() -> SuperModule = atom()
%%% | none
e() ->
exit('tTransport is abstract').
-isOpen(_This) -> e(), nil.
-open(_This) -> e(), nil.
-close(_This) -> e(), nil.
-read(_This, _Sz) -> e(), nil.
+isOpen(_This) ->
+ e(),
+ nil.
+
+effectful_open(This) ->
+ e(),
+ {nil, This}.
+
+effectful_close(This) ->
+ e(),
+ {nil, This}.
+
+read(_This, _Sz) ->
+ e(),
+ nil.
readAll(This, Sz) ->
readAll_loop(This, Sz, "", 0).
readAll_loop(This, Sz, Buff, Have) ->
- if
- Have < Sz ->
- Chunk = ?L1(read, Sz - Have),
-
- %% man gen_tcp:
- %% exactly Length bytes are returned, or an error;
- %% possibly discarding less than Length bytes of data when
- %% the socket gets closed from the other side.
-
- %% error_logger:info_msg("READ |~p|", [Chunk]),
-
- Have1 = Have + (Sz-Have), % length(Chunk)
- Buff1 = Buff ++ Chunk, % TODO: ++ efficiency?
- readAll_loop(This, Sz, Buff1, Have1);
- true ->
- Buff
+ if
+ Have < Sz ->
+ Chunk = ?L1(read, Sz - Have),
+
+ %% man gen_tcp:
+ %% exactly Length bytes are returned, or an error;
+ %% possibly discarding less than Length bytes of data when
+ %% the socket gets closed from the other side.
+
+ %% error_logger:info_msg("READ |~p|", [Chunk]),
+
+ Have1 = Have + (Sz-Have), % length(Chunk)
+ Buff1 = Buff ++ Chunk, % TODO: ++ efficiency?
+ readAll_loop(This, Sz, Buff1, Have1);
+ true ->
+ Buff
end.
effectful_write(This, _Buf) ->