aboutsummaryrefslogtreecommitdiffstats
path: root/test/transport_capabilities_protocol.erl
diff options
context:
space:
mode:
Diffstat (limited to 'test/transport_capabilities_protocol.erl')
-rw-r--r--test/transport_capabilities_protocol.erl53
1 files changed, 53 insertions, 0 deletions
diff --git a/test/transport_capabilities_protocol.erl b/test/transport_capabilities_protocol.erl
new file mode 100644
index 0000000..0f8bf9d
--- /dev/null
+++ b/test/transport_capabilities_protocol.erl
@@ -0,0 +1,53 @@
+-module(transport_capabilities_protocol).
+-behaviour(ranch_protocol).
+
+-export([start_link/4]).
+-export([init/4]).
+
+start_link(Ref, Socket, Transport, Opts) ->
+ Pid = spawn_link(?MODULE, init, [Ref, Socket, Transport, Opts]),
+ {ok, Pid}.
+
+init(Ref, Socket, Transport, _Opts = []) ->
+ ok = ranch:accept_ack(Ref),
+ loop(Socket, Transport).
+
+loop(Socket, Transport) ->
+ case Transport:recv(Socket, 0, 5000) of
+ {ok, Data} ->
+ Reply =
+ case check(Socket, Transport, Data) of
+ ok ->
+ <<"OK">>;
+ error ->
+ <<"ERROR">>
+ end,
+ Transport:send(Socket, Reply),
+ loop(Socket, Transport);
+ _ ->
+ ok = Transport:close(Socket)
+ end.
+
+check(Socket, Transport, <<"getopts/2">>) ->
+ case catch Transport:getopts(Socket, []) of
+ {ok, _} ->
+ ok;
+ _ ->
+ error
+ end;
+
+check(Socket, Transport, <<"getstat/1">>) ->
+ case catch Transport:getstat(Socket) of
+ {ok, _} ->
+ ok;
+ _ ->
+ error
+ end;
+
+check(Socket, Transport, <<"getstat/2">>) ->
+ case catch Transport:getstat(Socket, []) of
+ {ok, _} ->
+ ok;
+ _ ->
+ error
+ end.