aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorAndrew Thompson <[email protected]>2012-09-24 13:32:21 -0400
committerAndrew Thompson <[email protected]>2012-12-20 12:50:22 -0500
commit036fbd53189f0a43bd8348e517a17da0f00de980 (patch)
tree721b2159b79869459af39398f95e1fc38c9397c9 /test
parentf26401af19bddd74ddd1755041372c737a995b01 (diff)
downloadranch-036fbd53189f0a43bd8348e517a17da0f00de980.tar.gz
ranch-036fbd53189f0a43bd8348e517a17da0f00de980.tar.bz2
ranch-036fbd53189f0a43bd8348e517a17da0f00de980.zip
Add {socket, Socket} transport option, for accepting on existing sockets
Diffstat (limited to 'test')
-rw-r--r--test/acceptor_SUITE.erl53
1 files changed, 51 insertions, 2 deletions
diff --git a/test/acceptor_SUITE.erl b/test/acceptor_SUITE.erl
index 0b86a4d..5e8d9cf 100644
--- a/test/acceptor_SUITE.erl
+++ b/test/acceptor_SUITE.erl
@@ -29,10 +29,12 @@
%% ssl.
-export([ssl_accept_error/1]).
+-export([ssl_accept_socket/1]).
-export([ssl_active_echo/1]).
-export([ssl_echo/1]).
%% tcp.
+-export([tcp_accept_socket/1]).
-export([tcp_active_echo/1]).
-export([tcp_echo/1]).
-export([tcp_max_connections/1]).
@@ -50,11 +52,13 @@ groups() ->
tcp_echo,
tcp_max_connections,
tcp_max_connections_and_beyond,
- tcp_upgrade
+ tcp_upgrade,
+ tcp_accept_socket
]}, {ssl, [
ssl_accept_error,
ssl_active_echo,
- ssl_echo
+ ssl_echo,
+ ssl_accept_socket
]}, {misc, [
misc_bad_transport
]}].
@@ -108,6 +112,26 @@ ssl_accept_error(Config) ->
receive after 500 -> ok end,
true = is_process_alive(AcceptorPid).
+ssl_accept_socket(Config) ->
+ %%% XXX we can't do the spawn to test the controlling process change
+ %%% because of the bug in ssl
+ {ok, S} = ssl:listen(0,
+ [{certfile, ?config(data_dir, Config) ++ "cert.pem"}, binary,
+ {active, false}, {packet, raw}, {reuseaddr, true}]),
+ {ok, _} = ranch:start_listener(ssl_accept_socket, 1,
+ ranch_ssl, [{socket, S}], echo_protocol, []),
+ Port = ranch:get_port(ssl_accept_socket),
+ {ok, Socket} = ssl:connect("localhost", Port,
+ [binary, {active, false}, {packet, raw},
+ {certfile, ?config(data_dir, Config) ++ "cert.pem"}]),
+ ok = ssl:send(Socket, <<"TCP Ranch is working!">>),
+ {ok, <<"TCP Ranch is working!">>} = ssl:recv(Socket, 21, 1000),
+ ok = ranch:stop_listener(ssl_accept_socket),
+ {error, closed} = ssl:recv(Socket, 0, 1000),
+ %% Make sure the listener stopped.
+ {'EXIT', _} = begin catch ranch:get_port(ssl_accept_socket) end,
+ ok.
+
ssl_active_echo(Config) ->
{ok, _} = ranch:start_listener(ssl_active_echo, 1,
ranch_ssl, [{port, 0},
@@ -144,6 +168,31 @@ ssl_echo(Config) ->
%% tcp.
+tcp_accept_socket(_) ->
+ Ref = make_ref(),
+ Parent = self(),
+ spawn(fun() ->
+ {ok, S} = gen_tcp:listen(0, [binary, {active, false}, {packet, raw},
+ {reuseaddr, true}]),
+ {ok, _} = ranch:start_listener(tcp_accept_socket, 1,
+ ranch_tcp, [{socket, S}], echo_protocol, []),
+ Parent ! Ref
+ end),
+ receive
+ Ref -> ok
+ end,
+
+ Port = ranch:get_port(tcp_accept_socket),
+ {ok, Socket} = gen_tcp:connect("localhost", Port,
+ [binary, {active, false}, {packet, raw}]),
+ ok = gen_tcp:send(Socket, <<"TCP Ranch is working!">>),
+ {ok, <<"TCP Ranch is working!">>} = gen_tcp:recv(Socket, 21, 1000),
+ ok = ranch:stop_listener(tcp_accept_socket),
+ {error, closed} = gen_tcp:recv(Socket, 0, 1000),
+ %% Make sure the listener stopped.
+ {'EXIT', _} = begin catch ranch:get_port(tcp_accept_socket) end,
+ ok.
+
tcp_active_echo(_) ->
{ok, _} = ranch:start_listener(tcp_active_echo, 1,
ranch_tcp, [{port, 0}], active_echo_protocol, []),