THRIFT-785. erlang: Eliminate log spew with framed transport
authorDavid Reiss <dreiss@apache.org>
Mon, 30 Aug 2010 22:11:58 +0000 (22:11 +0000)
committerDavid Reiss <dreiss@apache.org>
Mon, 30 Aug 2010 22:11:58 +0000 (22:11 +0000)
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

lib/erl/src/thrift_framed_transport.erl

index 9b90112..2c5531a 100644 (file)
@@ -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, <<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