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 2008/06/11 03:00:45 UTC

svn commit: r666439 - in /incubator/thrift/trunk/lib/alterl/src: thrift_buffered_transport.erl thrift_client.erl

Author: dreiss
Date: Tue Jun 10 18:00:45 2008
New Revision: 666439

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

Modified:
    incubator/thrift/trunk/lib/alterl/src/thrift_buffered_transport.erl
    incubator/thrift/trunk/lib/alterl/src/thrift_client.erl

Modified: incubator/thrift/trunk/lib/alterl/src/thrift_buffered_transport.erl
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/alterl/src/thrift_buffered_transport.erl?rev=666439&r1=666438&r2=666439&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/alterl/src/thrift_buffered_transport.erl (original)
+++ incubator/thrift/trunk/lib/alterl/src/thrift_buffered_transport.erl Tue Jun 10 18:00:45 2008
@@ -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 = []}}.
 

Modified: incubator/thrift/trunk/lib/alterl/src/thrift_client.erl
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/alterl/src/thrift_client.erl?rev=666439&r1=666438&r2=666439&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/alterl/src/thrift_client.erl (original)
+++ incubator/thrift/trunk/lib/alterl/src/thrift_client.erl Tue Jun 10 18:00:45 2008
@@ -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.
 
 %%--------------------------------------------------------------------