From: David Reiss Date: Mon, 30 Aug 2010 22:11:58 +0000 (+0000) Subject: THRIFT-785. erlang: Eliminate log spew with framed transport X-Git-Tag: 0.5.0~101 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=5f11084c060e1cfcb48285d4098fe416f9334fd6;p=common%2Fthrift.git THRIFT-785. erlang: Eliminate log spew with framed transport If we get an error when reading from the underlying transport, propagate it out instead of dying and generating error logs. git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@991005 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/lib/erl/src/thrift_framed_transport.erl b/lib/erl/src/thrift_framed_transport.erl index 9b90112c..2c5531ae 100644 --- a/lib/erl/src/thrift_framed_transport.erl +++ b/lib/erl/src/thrift_framed_transport.erl @@ -72,24 +72,35 @@ read(State0 = #framed_transport{wrapped = Wrapped0, read_buffer = RBuf}, case iolist_size(RBuf) of 0 -> %% read the frame length - {WrappedS1, {ok, <>}} = - thrift_transport:read(Wrapped0, 4), - %% then read the data - {WrappedS2, {ok, Bin}} = - thrift_transport:read(WrappedS1, FrameLen), - {WrappedS2, {Bin, erlang:byte_size(Bin)}}; + case thrift_transport:read(Wrapped0, 4) of + {WrappedS1, + {ok, <>}} -> + %% then read the data + case thrift_transport:read(WrappedS1, FrameLen) of + {WrappedS2, {ok, Bin}} -> + {WrappedS2, {Bin, erlang:byte_size(Bin)}}; + {WrappedS2, {error, Reason1}} -> + {WrappedS2, {error, Reason1}} + end; + {WrappedS1, {error, Reason2}} -> + {WrappedS1, {error, Reason2}} + end; Sz -> {Wrapped0, {RBuf, Sz}} end, %% pull off Give bytes, return them to the user, leave the rest in the buffer - Give = min(RBuf1Size, Len), - <> = iolist_to_binary(RBuf1), - - Response = {ok, Data}, - State1 = State0#framed_transport{wrapped = Wrapped1, read_buffer=RBuf2}, - - {State1, Response}. + case RBuf1 of + error -> + { State0#framed_transport {wrapped = Wrapped1, read_buffer = [] }, + {RBuf1, RBuf1Size} }; + _ -> + Give = min(RBuf1Size, Len), + <> = iolist_to_binary(RBuf1), + + { State0#framed_transport{wrapped = Wrapped1, read_buffer=RBuf2}, + {ok, Data} } + end. %%-------------------------------------------------------------------- %% Internal functions