From a1650fe55cfdba6c5cad1f09e3142b23b24b66c9 Mon Sep 17 00:00:00 2001 From: Christopher Piro Date: Thu, 15 Nov 2007 06:26:27 +0000 Subject: [PATCH] [thrift] make open and close `effectful' in Erlang client Summary: make uniform across all tTransports. god i want `effectful' to go away dead. soon. Reviewed By: eletuchy Test Plan: ok Revert Plan: ok git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665338 13f79535-47bb-0310-9956-ffa450edef68 --- lib/erl/src/transport/tBufferedTransport.erl | 20 +++---- lib/erl/src/transport/tTransport.erl | 57 ++++++++++++-------- 2 files changed, 45 insertions(+), 32 deletions(-) diff --git a/lib/erl/src/transport/tBufferedTransport.erl b/lib/erl/src/transport/tBufferedTransport.erl index 3c0a0460..18d9af9f 100644 --- a/lib/erl/src/transport/tBufferedTransport.erl +++ b/lib/erl/src/transport/tBufferedTransport.erl @@ -1,6 +1,6 @@ %%% 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/ @@ -15,7 +15,7 @@ -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 @@ -25,11 +25,11 @@ ?DEFINE_ATTR(super); ?DEFINE_ATTR(transport); ?DEFINE_ATTR(wbuf). - + %%% %%% behavior callbacks %%% - + %%% super() -> SuperModule = atom() %%% | none @@ -58,13 +58,15 @@ isOpen(This) -> 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), @@ -77,7 +79,7 @@ effectful_write(This, Buf) -> % be sure to rebind This to the retval 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, ""), diff --git a/lib/erl/src/transport/tTransport.erl b/lib/erl/src/transport/tTransport.erl index a7293be6..73bcf72d 100644 --- a/lib/erl/src/transport/tTransport.erl +++ b/lib/erl/src/transport/tTransport.erl @@ -1,6 +1,6 @@ %%% 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/ @@ -15,7 +15,7 @@ -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 @@ -27,7 +27,7 @@ %%% %%% behavior callbacks %%% - + %%% super() -> SuperModule = atom() %%% | none @@ -53,31 +53,42 @@ new() -> 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) -> -- 2.17.1