Repository: thrift Updated Branches: refs/heads/master e58ed1ad3 -> ef3cf819e
THRIFT-3087 Pass on errors like "connection closed" Client: Erlang Patch: ÐндÑей ÐеÑелов and Nobuaki Sukegawa This closes #599 Project: http://git-wip-us.apache.org/repos/asf/thrift/repo Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/54790993 Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/54790993 Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/54790993 Branch: refs/heads/master Commit: 547909933c25cbf0b8d2c91958dbd2972320513a Parents: e58ed1a Author: ÐндÑей ÐеÑелов <[email protected]> Authored: Wed Aug 26 17:52:19 2015 +0300 Committer: Nobuaki Sukegawa <[email protected]> Committed: Fri Nov 27 00:08:27 2015 +0900 ---------------------------------------------------------------------- lib/erl/src/thrift_client.erl | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/thrift/blob/54790993/lib/erl/src/thrift_client.erl ---------------------------------------------------------------------- diff --git a/lib/erl/src/thrift_client.erl b/lib/erl/src/thrift_client.erl index 7bf50a5..1a9cb50 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) ->
