erlang: Refactor thrift_transport and all transport implementations

Note that the buffering transports still use a separate process to
maintain their state.  This change just changes them to use a
"return-the-new-version"-style API.

git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@990989 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/erl/src/thrift_binary_protocol.erl b/lib/erl/src/thrift_binary_protocol.erl
index fcb072b..796089c 100644
--- a/lib/erl/src/thrift_binary_protocol.erl
+++ b/lib/erl/src/thrift_binary_protocol.erl
@@ -61,12 +61,12 @@
 
 
 flush_transport(This = #binary_protocol{transport = Transport}) ->
-    Result = thrift_transport:flush(Transport),
-    {This, Result}.
+    {NewTransport, Result} = thrift_transport:flush(Transport),
+    {This#binary_protocol{transport = NewTransport}, Result}.
 
 close_transport(This = #binary_protocol{transport = Transport}) ->
-    Result = thrift_transport:close(Transport),
-    {This, Result}.
+    {NewTransport, Result} = thrift_transport:close(Transport),
+    {This#binary_protocol{transport = NewTransport}, Result}.
 
 %%%
 %%% instance methods
@@ -166,8 +166,8 @@
 
 %% Data :: iolist()
 write(This = #binary_protocol{transport = Trans}, Data) ->
-    Result = thrift_transport:write(Trans, Data),
-    {This, Result}.
+    {NewTransport, Result} = thrift_transport:write(Trans, Data),
+    {This#binary_protocol{transport = NewTransport}, Result}.
 
 %%
 
@@ -312,8 +312,8 @@
     {#binary_protocol{}, {ok, binary()} | {error, _Reason}}.
 read_data(This, 0) -> {This, {ok, <<>>}};
 read_data(This = #binary_protocol{transport = Trans}, Len) when is_integer(Len) andalso Len > 0 ->
-    Result = thrift_transport:read(Trans, Len),
-    {This, Result}.
+    {NewTransport, Result} = thrift_transport:read(Trans, Len),
+    {This#binary_protocol{transport = NewTransport}, Result}.
 
 
 %%%% FACTORY GENERATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%