add a close to thrift_client to close the underlying transport

Reviewed By: eletuchy

Notes: the thrift_buffered_transport exits with {normal,{gen_server,call,[Pid,close]}} right now, but it should only exit with normal.  marked todo.


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@666439 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/alterl/src/thrift_buffered_transport.erl b/lib/alterl/src/thrift_buffered_transport.erl
index d6628ac..4cf4a36 100644
--- a/lib/alterl/src/thrift_buffered_transport.erl
+++ b/lib/alterl/src/thrift_buffered_transport.erl
@@ -94,6 +94,8 @@
 %% Description: Initiates the server
 %%--------------------------------------------------------------------
 init([Wrapped]) ->
+    %% TODO(cpiro): need to trap exits here so when transport exits
+    %% normally from under our feet we exit normally
     {ok, #state{wrapped = Wrapped,
                 buffer = []}}.
 
diff --git a/lib/alterl/src/thrift_client.erl b/lib/alterl/src/thrift_client.erl
index e1e78e7..d2ac692 100644
--- a/lib/alterl/src/thrift_client.erl
+++ b/lib/alterl/src/thrift_client.erl
@@ -10,7 +10,7 @@
 -behaviour(gen_server).
 
 %% API
--export([start_link/3, call/3]).
+-export([start_link/3, call/3, close/1]).
 
 %% gen_server callbacks
 -export([init/1, handle_call/3, handle_cast/2, handle_info/2,
@@ -40,6 +40,9 @@
         {exception, Exception} -> throw(Exception)
     end.
 
+close(Client) when is_pid(Client) ->
+    gen_server:call(Client, close).
+
 %%====================================================================
 %% gen_server callbacks
 %%====================================================================
@@ -93,8 +96,10 @@
                 end
         end,
 
-    {reply, Result, State}.
+    {reply, Result, State};
 
+handle_call(close, _From, State = #state{protocol = Protocol}) ->
+    {stop, shutdown, ok, State}.
 
 %%--------------------------------------------------------------------
 %% Function: handle_cast(Msg, State) -> {noreply, State} |
@@ -121,7 +126,8 @@
 %% cleaning up. When it returns, the gen_server terminates with Reason.
 %% The return value is ignored.
 %%--------------------------------------------------------------------
-terminate(_Reason, _State) ->
+terminate(_Reason, State = #state{protocol = Protocol}) ->
+    thrift_protocol:close_transport(Protocol),
     ok.
 
 %%--------------------------------------------------------------------