Skip to content

Commit

Permalink
pass a real #stateless_context{} on calls initiated through run_state…
Browse files Browse the repository at this point in the history
…less_binary_request/3
  • Loading branch information
fjl committed Feb 10, 2012
1 parent 8eb156d commit e062524
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/hello_stateless_handler.erl
Expand Up @@ -127,8 +127,6 @@ transport_param(Key, Context) ->
%% Please take this into consideration when designing your system.
-spec transport_param(atom(), context(), any()) -> any().
transport_param(Key, #stateless_context{transport_params = Params}, Default) ->
transport_param(Key, Params, Default);
transport_param(Key, Params, Default) ->
proplists:get_value(Key, Params, Default).

%% ----------------------------------------------------------------------------------------------------
Expand All @@ -137,10 +135,9 @@ transport_param(Key, Params, Default) ->
%% @doc stateless handler process function for hello_binding
-spec handler(#binding{}, hello_binding:peer(), pid(), hello:transport_params()) -> any().
handler(#binding{protocol = Protocol, log_url = Endpoint, callback_mod = CallbackModule}, Peer, Transport, TransportParams) ->
Context = #stateless_context{transport_params = TransportParams},
receive
{?INCOMING_MSG_MSG, Message} ->
case run_binary_request(Protocol, CallbackModule, Context, Message) of
case run_binary_request(Protocol, CallbackModule, TransportParams, Message) of
{ok, Request, Response} ->
hello_request_log:request(CallbackModule, self(), Endpoint, Request, Response),
BinResp = hello_proto:encode(Response),
Expand All @@ -159,9 +156,10 @@ handler(#binding{protocol = Protocol, log_url = Endpoint, callback_mod = Callbac
end.

%% @private
-spec run_binary_request(module(), module(), #stateless_context{}, binary()) ->
-spec run_binary_request(module(), module(), hello:transport_params(), binary()) ->
{ok, hello_proto:request(), hello_proto:response()} | {error, hello_proto:response()}.
run_binary_request(Protocol, CallbackModule, Context, BinRequest) ->
run_binary_request(Protocol, CallbackModule, TransportParams, BinRequest) ->
Context = #stateless_context{transport_params = TransportParams},
case hello_proto:decode(Protocol, BinRequest) of
Req = #request{} ->
{ok, Req, do_single_request(CallbackModule, Context, Req)};
Expand Down

0 comments on commit e062524

Please sign in to comment.