You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by dr...@apache.org on 2010/08/31 00:11:58 UTC

svn commit: r991005 - /incubator/thrift/trunk/lib/erl/src/thrift_framed_transport.erl

Author: dreiss
Date: Mon Aug 30 22:11:58 2010
New Revision: 991005

URL: http://svn.apache.org/viewvc?rev=991005&view=rev
Log:
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.

Modified:
    incubator/thrift/trunk/lib/erl/src/thrift_framed_transport.erl

Modified: incubator/thrift/trunk/lib/erl/src/thrift_framed_transport.erl
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/erl/src/thrift_framed_transport.erl?rev=991005&r1=991004&r2=991005&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/erl/src/thrift_framed_transport.erl (original)
+++ incubator/thrift/trunk/lib/erl/src/thrift_framed_transport.erl Mon Aug 30 22:11:58 2010
@@ -72,24 +72,35 @@ read(State0 = #framed_transport{wrapped 
         case iolist_size(RBuf) of
             0 ->
                 %% read the frame length
-                {WrappedS1, {ok, <<FrameLen:32/integer-signed-big, _/binary>>}} =
-                    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, <<FrameLen:32/integer-signed-big, _/binary>>}} ->
+                    %% 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),
-    <<Data:Give/binary, RBuf2/binary>> = 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),
+        <<Data:Give/binary, RBuf2/binary>> = iolist_to_binary(RBuf1),
+
+        { State0#framed_transport{wrapped = Wrapped1, read_buffer=RBuf2},
+          {ok, Data} }
+    end.
 
 %%--------------------------------------------------------------------
 %% Internal functions