-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson_sample.yaws
43 lines (33 loc) · 1.3 KB
/
json_sample.yaws
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<erl module=sample_mod>
-compile(export_all).
out(A) ->
Peer = if
tuple(A#arg.clisock),
element(1, A#arg.clisock) == sslsocket ->
ssl:peername(A#arg.clisock);
true ->
inet:peername(A#arg.clisock)
end,
{ok,{IP,_}} = Peer,
A2=A#arg{state = [{ip, IP}]},
yaws_rpc:handler_session(A2, {?MODULE, counter}).
counter([{ip, IP}] = _State, {call, errortest, Value} = _Request, Session) ->
io:format("Request = ~p~n", [_Request]),
{ false, { error, "Expected failure" } };
counter([{ip, IP}] = _State, {call, test1, Value} = _Request, Session) ->
io:format("Request = ~p~n", [_Request]),
IPStr = io_lib:format("Client ip is ~p~n" , [ IP ]),
OldSession = io_lib:format("Request is: ~p~nOld session value "
"is ~p~n", [ _Request, Session ]),
case Session of
undefined -> % create new session
NewSession = 0;
10 -> % reset session after reaching 10
NewSession = undefined;
N ->
NewSession = N + 1
end,
NewVal = io_lib:format("New session value is ~p ~n", [ NewSession ]),
Str = lists:flatten([IPStr,OldSession,NewVal]),
{true, 0, NewSession, {response, Str }}.
</erl>