From 547909933c25cbf0b8d2c91958dbd2972320513a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9=20=D0=92=D0=B5=D1=81?= =?UTF-8?q?=D0=B5=D0=BB=D0=BE=D0=B2?= Date: Wed, 26 Aug 2015 17:52:19 +0300 Subject: =?UTF-8?q?THRIFT-3087=20Pass=20on=20errors=20like=20"connection?= =?UTF-8?q?=20closed"=20Client:=20Erlang=20Patch:=20=D0=90=D0=BD=D0=B4?= =?UTF-8?q?=D1=80=D0=B5=D0=B9=20=D0=92=D0=B5=D1=81=D0=B5=D0=BB=D0=BE=D0=B2?= =?UTF-8?q?=20and=20Nobuaki=20Sukegawa?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This closes #599 --- lib/erl/src/thrift_client.erl | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'lib/erl') diff --git a/lib/erl/src/thrift_client.erl b/lib/erl/src/thrift_client.erl index 7bf50a5c2..1a9cb50a4 100644 --- a/lib/erl/src/thrift_client.erl +++ b/lib/erl/src/thrift_client.erl @@ -63,7 +63,7 @@ close(#tclient{protocol=Protocol}) -> %%-------------------------------------------------------------------- %%% Internal functions %%-------------------------------------------------------------------- --spec send_function_call(#tclient{}, atom(), list()) -> {sync | async | {error, any()}, #tclient{}}. +-spec send_function_call(#tclient{}, atom(), list()) -> {ok | {error, any()}, #tclient{}}. send_function_call(Client = #tclient{service = Service}, Function, Args) -> {Params, Reply} = try {Service:function_info(Function, params_type), Service:function_info(Function, reply_type)} @@ -82,17 +82,21 @@ send_function_call(Client = #tclient{service = Service}, Function, Args) -> end. -spec write_message(#tclient{}, atom(), list(), {struct, list()}, integer()) -> - {ok, #tclient{}}. + {ok | {error, any()}, #tclient{}}. write_message(Client = #tclient{protocol = P0, seqid = Seq}, Function, Args, Params, MsgType) -> - {P1, ok} = thrift_protocol:write(P0, #protocol_message_begin{ - name = atom_to_list(Function), - type = MsgType, - seqid = Seq - }), - {P2, ok} = thrift_protocol:write(P1, {Params, list_to_tuple([Function|Args])}), - {P3, ok} = thrift_protocol:write(P2, message_end), - {P4, ok} = thrift_protocol:flush_transport(P3), - {ok, Client#tclient{protocol = P4}}. + try + {P1, ok} = thrift_protocol:write(P0, #protocol_message_begin{ + name = atom_to_list(Function), + type = MsgType, + seqid = Seq + }), + {P2, ok} = thrift_protocol:write(P1, {Params, list_to_tuple([Function|Args])}), + {P3, ok} = thrift_protocol:write(P2, message_end), + {P4, ok} = thrift_protocol:flush_transport(P3), + {ok, Client#tclient{protocol = P4}} + catch + error:{badmatch, {_, {error, _} = Error}} -> {Error, Client} + end. -spec receive_function_result(#tclient{}, atom()) -> {#tclient{}, {ok, any()} | {error, any()}}. receive_function_result(Client = #tclient{service = Service}, Function) -> -- cgit v1.2.1