Browse Source

Use ssl:handshake instead of ssl:ssl_accept

This makes Ranch require OTP-21+. The function ranch:accept_ack/1
was also removed in this commit.
Loïc Hoguin 6 years ago
parent
commit
e92171a8f8
7 changed files with 5 additions and 85 deletions
  1. 2 2
      Makefile
  2. 2 1
      doc/src/manual/ranch.asciidoc
  3. 0 8
      src/ranch.erl
  4. 1 13
      src/ranch_ssl.erl
  5. 0 6
      src/ranch_tcp.erl
  6. 0 22
      test/accept_ack_protocol.erl
  7. 0 33
      test/acceptor_SUITE.erl

+ 2 - 2
Makefile

@@ -25,10 +25,10 @@ dep_havoc = git https://github.com/ankhers/havoc master
 dep_ci.erlang.mk = git https://github.com/ninenines/ci.erlang.mk master
 DEP_EARLY_PLUGINS = ci.erlang.mk
 
-AUTO_CI_OTP ?= OTP-19+
+AUTO_CI_OTP ?= OTP-21+
 AUTO_CI_HIPE ?= OTP-LATEST
 # AUTO_CI_ERLLVM ?= OTP-LATEST
-AUTO_CI_WINDOWS ?= OTP-19+
+AUTO_CI_WINDOWS ?= OTP-21+
 
 # Standard targets.
 

+ 2 - 1
doc/src/manual/ranch.asciidoc

@@ -25,7 +25,6 @@ Suspend/resume:
 
 Connections:
 
-* ranch:accept_ack(3) - Deprecated in favor of link:man:ranch:handshake(3)[ranch:handshake(3)]
 * link:man:ranch:handshake(3)[ranch:handshake(3)] - Perform the transport handshake
 * link:man:ranch:recv_proxy_header(3)[ranch:recv_proxy_header(3)] - Receive the PROXY protocol header
 * link:man:ranch:remove_connection(3)[ranch:remove_connection(3)] - Remove connection from the count
@@ -131,6 +130,8 @@ Unique name used to refer to a listener.
 
 == Changelog
 
+* *2.0*: The function `ranch:accept_ack/1` was removed in favor of
+         link:man:ranch:handshake(3)[ranch:handshake(3)].
 * *2.0*: The option `max_connections` is now per connection supervisor.
 * *2.0*: The `num_conns_sup` option was added.
 * *2.0*: The `socket` option was removed.

+ 0 - 8
src/ranch.erl

@@ -20,7 +20,6 @@
 -export([suspend_listener/1]).
 -export([resume_listener/1]).
 -export([child_spec/5]).
--export([accept_ack/1]).
 -export([handshake/1]).
 -export([handshake/2]).
 -export([recv_proxy_header/2]).
@@ -44,8 +43,6 @@
 -export([require/1]).
 -export([log/4]).
 
--deprecated([accept_ack/1]).
-
 -type max_conns() :: non_neg_integer() | infinity.
 -export_type([max_conns/0]).
 
@@ -145,11 +142,6 @@ child_spec(Ref, Transport, TransOpts0, Protocol, ProtoOpts) ->
 		Ref, Transport, TransOpts, Protocol, ProtoOpts
 	]}, permanent, infinity, supervisor, [ranch_listener_sup]}.
 
--spec accept_ack(ref()) -> ok.
-accept_ack(Ref) ->
-	{ok, _} = handshake(Ref),
-	ok.
-
 -spec handshake(ref()) -> {ok, ranch_transport:socket()}.
 handshake(Ref) ->
 	handshake(Ref, []).

+ 1 - 13
src/ranch_ssl.erl

@@ -15,17 +15,12 @@
 -module(ranch_ssl).
 -behaviour(ranch_transport).
 
--ifdef(OTP_RELEASE).
--compile({nowarn_deprecated_function, [{ssl, ssl_accept, 3}]}).
--endif.
-
 -export([name/0]).
 -export([secure/0]).
 -export([messages/0]).
 -export([listen/1]).
 -export([disallowed_listen_options/0]).
 -export([accept/2]).
--export([accept_ack/2]).
 -export([handshake/3]).
 -export([connect/3]).
 -export([connect/4]).
@@ -131,17 +126,10 @@ disallowed_listen_options() ->
 accept(LSocket, Timeout) ->
 	ssl:transport_accept(LSocket, Timeout).
 
--spec accept_ack(ssl:sslsocket(), timeout()) -> ok.
-accept_ack(CSocket, Timeout) ->
-	{ok, _} = handshake(CSocket, [], Timeout),
-	ok.
-
 -spec handshake(inet:socket() | ssl:sslsocket(), opts(), timeout())
 	-> {ok, ssl:sslsocket()} | {error, any()}.
 handshake(CSocket, Opts, Timeout) ->
-	case ssl:ssl_accept(CSocket, Opts, Timeout) of
-		ok ->
-			{ok, CSocket};
+	case ssl:handshake(CSocket, Opts, Timeout) of
 		{ok, NewSocket} ->
 			{ok, NewSocket};
 		Error = {error, _} ->

+ 0 - 6
src/ranch_tcp.erl

@@ -21,7 +21,6 @@
 -export([listen/1]).
 -export([disallowed_listen_options/0]).
 -export([accept/2]).
--export([accept_ack/2]).
 -export([handshake/3]).
 -export([connect/3]).
 -export([connect/4]).
@@ -101,11 +100,6 @@ disallowed_listen_options() ->
 accept(LSocket, Timeout) ->
 	gen_tcp:accept(LSocket, Timeout).
 
--spec accept_ack(inet:socket(), timeout()) -> ok.
-accept_ack(CSocket, Timeout) ->
-	{ok, _} = handshake(CSocket, [], Timeout),
-	ok.
-
 -spec handshake(inet:socket(), opts(), timeout()) -> {ok, inet:socket()}.
 handshake(CSocket, _, _) ->
 	{ok, CSocket}.

+ 0 - 22
test/accept_ack_protocol.erl

@@ -1,22 +0,0 @@
--module(accept_ack_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} ->
-			Transport:send(Socket, Data),
-			loop(Socket, Transport);
-		_ ->
-			ok = Transport:close(Socket)
-	end.

+ 0 - 33
test/acceptor_SUITE.erl

@@ -31,7 +31,6 @@ groups() ->
 		tcp_active_echo,
 		tcp_echo,
 		tcp_graceful,
-		tcp_accept_ack,
 		tcp_inherit_options,
 		tcp_max_connections,
 		tcp_max_connections_and_beyond,
@@ -49,7 +48,6 @@ groups() ->
 		ssl_active_echo,
 		ssl_echo,
 		ssl_graceful,
-		ssl_accept_ack,
 		ssl_sni_echo,
 		ssl_sni_fail,
 		ssl_upgrade_from_tcp,
@@ -543,22 +541,6 @@ ssl_graceful(_) ->
 	{'EXIT', _} = begin catch ranch:get_port(Name) end,
 	ok.
 
-ssl_accept_ack(_) ->
-	doc("Ensure accept_ack works with SSL transport."),
-	Name = name(),
-	Opts = ct_helper:get_certs_from_ets(),
-	{ok, _} = ranch:start_listener(Name,
-		ranch_ssl, Opts,
-		accept_ack_protocol, []),
-	Port = ranch:get_port(Name),
-	{ok, Socket} = ssl:connect("localhost", Port, [binary, {active, false}, {packet, raw}]),
-	ok = ssl:send(Socket, <<"SSL transport accept_ack is working!">>),
-	{ok, <<"SSL transport accept_ack is working!">>} = ssl:recv(Socket, 36, 1000),
-	ok = ranch:stop_listener(Name),
-	{error, closed} = ssl:recv(Socket, 0, 1000),
-	{'EXIT', _} = begin catch ranch:get_port(Name) end,
-	ok.
-
 ssl_getopts_capability(_) ->
 	doc("Ensure getopts/2 capability."),
 	Name=name(),
@@ -712,21 +694,6 @@ tcp_graceful(_) ->
 	{'EXIT', _} = begin catch ranch:get_port(Name) end,
 	ok.
 
-tcp_accept_ack(_) ->
-	doc("Ensure accept_ack works with TCP transport."),
-	Name = name(),
-	{ok, _} = ranch:start_listener(Name,
-		ranch_tcp, #{},
-		accept_ack_protocol, []),
-	Port = ranch:get_port(Name),
-	{ok, Socket} = gen_tcp:connect("localhost", Port, [binary, {active, false}, {packet, raw}]),
-	ok = gen_tcp:send(Socket, <<"TCP transport accept_ack is working!">>),
-	{ok, <<"TCP transport accept_ack is working!">>} = gen_tcp:recv(Socket, 36, 1000),
-	ok = ranch:stop_listener(Name),
-	{error, closed} = gen_tcp:recv(Socket, 0, 1000),
-	{'EXIT', _} = begin catch ranch:get_port(Name) end,
-	ok.
-
 tcp_inherit_options(_) ->
 	doc("Ensure TCP options are inherited in the protocol."),
 	Name = name(),