From c49dd1e9e2bdeae5d48f7b9a4d57d3414fbe3dc0 Mon Sep 17 00:00:00 2001 From: David Reiss Date: Wed, 11 Jun 2008 01:02:39 +0000 Subject: [PATCH] adding explicit timeout handling and error_logging git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@666453 13f79535-47bb-0310-9956-ffa450edef68 --- lib/alterl/src/thrift_buffered_transport.erl | 2 +- lib/alterl/src/thrift_processor.erl | 3 +++ lib/alterl/src/thrift_socket_transport.erl | 8 +++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/alterl/src/thrift_buffered_transport.erl b/lib/alterl/src/thrift_buffered_transport.erl index 575245db..c7ab295b 100644 --- a/lib/alterl/src/thrift_buffered_transport.erl +++ b/lib/alterl/src/thrift_buffered_transport.erl @@ -73,7 +73,7 @@ close(Transport) -> %% Description: Reads data through from the wrapped transoprt %%-------------------------------------------------------------------- read(Transport, Len) when is_integer(Len) -> - gen_server:call(Transport, {read, Len}). + gen_server:call(Transport, {read, Len}, _Timeout=10000). %%==================================================================== %% gen_server callbacks diff --git a/lib/alterl/src/thrift_processor.erl b/lib/alterl/src/thrift_processor.erl index 233c3090..0ad65571 100644 --- a/lib/alterl/src/thrift_processor.erl +++ b/lib/alterl/src/thrift_processor.erl @@ -30,6 +30,9 @@ loop(State = #thrift_processor{in_protocol = IProto, type = ?tMessageType_CALL} -> ok = handle_function(State, list_to_atom(Function)), loop(State); + {error, timeout} -> + thrift_protocol:close_transport(OProto), + ok; {error, closed} -> %% error_logger:info_msg("Client disconnected~n"), thrift_protocol:close_transport(OProto), diff --git a/lib/alterl/src/thrift_socket_transport.erl b/lib/alterl/src/thrift_socket_transport.erl index 0b463cc9..9d15ee16 100644 --- a/lib/alterl/src/thrift_socket_transport.erl +++ b/lib/alterl/src/thrift_socket_transport.erl @@ -29,7 +29,13 @@ write(#data{socket = Socket}, Data) -> read(#data{socket=Socket, recv_timeout=Timeout}, Len) when is_integer(Len), Len >= 0 -> - gen_tcp:recv(Socket, Len, Timeout). + case gen_tcp:recv(Socket, Len, Timeout) of + Err = {error, timeout} -> + error_logger:error_msg("read timeout for conn with ~p", [inet:peername(Socket)]), + gen_tcp:close(Socket), + Err; + Data -> Data + end. %% We can't really flush - everything is flushed when we write flush(_) -> -- 2.17.1