From 464e3000540738f9864626f4afe6036bcf89d2f5 Mon Sep 17 00:00:00 2001 From: David Reiss Date: Wed, 11 Jun 2008 01:00:45 +0000 Subject: [PATCH] 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 --- lib/alterl/src/thrift_buffered_transport.erl | 2 ++ lib/alterl/src/thrift_client.erl | 12 +++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/alterl/src/thrift_buffered_transport.erl b/lib/alterl/src/thrift_buffered_transport.erl index d6628ac1..4cf4a361 100644 --- a/lib/alterl/src/thrift_buffered_transport.erl +++ b/lib/alterl/src/thrift_buffered_transport.erl @@ -94,6 +94,8 @@ read(Transport, Len) when is_integer(Len) -> %% 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 e1e78e77..d2ac6921 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 @@ call(Client, Function, Args) {exception, Exception} -> throw(Exception) end. +close(Client) when is_pid(Client) -> + gen_server:call(Client, close). + %%==================================================================== %% gen_server callbacks %%==================================================================== @@ -93,8 +96,10 @@ handle_call({call, Function, Args}, _From, State = #state{service = Service, 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 @@ handle_info(_Info, State) -> %% 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. %%-------------------------------------------------------------------- -- 2.17.1