erlang: test_{client,server}: Allow framed_transport to be used

git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@990988 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
David Reiss 2010-08-30 22:05:41 +00:00
parent 2c8d228fa7
commit a508b336db
2 changed files with 58 additions and 7 deletions

View File

@ -23,11 +23,34 @@
-include("thriftTest_types.hrl"). -include("thriftTest_types.hrl").
start() -> start(["9090"]). -record(options, {port = 9090,
start([PortStr]) -> client_opts = []}).
Port = list_to_integer(PortStr),
parse_args(Args) -> parse_args(Args, #options{}).
parse_args([], Opts) -> Opts;
parse_args([Head | Rest], Opts) ->
NewOpts =
case catch list_to_integer(Head) of
Port when is_integer(Port) ->
Opts#options{port = Port};
_Else ->
case Head of
"framed" ->
Opts#options{client_opts = [{framed, true} | Opts#options.client_opts]};
"" ->
Opts;
_Else ->
erlang:error({bad_arg, Head})
end
end,
parse_args(Rest, NewOpts).
start() -> start([]).
start(Args) ->
#options{port = Port, client_opts = ClientOpts} = parse_args(Args),
{ok, Client0} = thrift_client_util:new( {ok, Client0} = thrift_client_util:new(
"127.0.0.1", Port, thriftTest_thrift, []), "127.0.0.1", Port, thriftTest_thrift, ClientOpts),
DemoXtruct = #xtruct{ DemoXtruct = #xtruct{
string_thing = <<"Zero">>, string_thing = <<"Zero">>,

View File

@ -19,14 +19,42 @@
-module(test_server). -module(test_server).
-export([start_link/1, handle_function/2]). -export([go/0, go/1, start_link/2, handle_function/2]).
-include("thriftTest_types.hrl"). -include("thriftTest_types.hrl").
start_link(Port) -> -record(options, {port = 9090,
server_opts = []}).
parse_args(Args) -> parse_args(Args, #options{}).
parse_args([], Opts) -> Opts;
parse_args([Head | Rest], Opts) ->
NewOpts =
case catch list_to_integer(Head) of
Port when is_integer(Port) ->
Opts#options{port = Port};
_Else ->
case Head of
"framed" ->
Opts#options{server_opts = [{framed, true} | Opts#options.server_opts]};
"" ->
Opts;
_Else ->
erlang:error({bad_arg, Head})
end
end,
parse_args(Rest, NewOpts).
go() -> go([]).
go(Args) ->
#options{port = Port, server_opts = ServerOpts} = parse_args(Args),
spawn(fun() -> start_link(Port, ServerOpts), receive after infinity -> ok end end).
start_link(Port, ServerOpts) ->
thrift_socket_server:start([{handler, ?MODULE}, thrift_socket_server:start([{handler, ?MODULE},
{service, thriftTest_thrift}, {service, thriftTest_thrift},
{port, Port}]). {port, Port}] ++
ServerOpts).
handle_function(testVoid, {}) -> handle_function(testVoid, {}) ->