Skip to content

Commit

Permalink
Use ssl:handshake instead of ssl:ssl_accept
Browse files Browse the repository at this point in the history
This makes Ranch require OTP-21+. The function ranch:accept_ack/1
was also removed in this commit.
  • Loading branch information
essen committed May 9, 2019
1 parent 34758e9 commit e92171a
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 85 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
3 changes: 2 additions & 1 deletion doc/src/manual/ranch.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 0 additions & 8 deletions src/ranch.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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]).
Expand All @@ -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]).

Expand Down Expand Up @@ -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, []).
Expand Down
14 changes: 1 addition & 13 deletions src/ranch_ssl.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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]).
Expand Down Expand Up @@ -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, _} ->
Expand Down
6 changes: 0 additions & 6 deletions src/ranch_tcp.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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]).
Expand Down Expand Up @@ -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}.
Expand Down
22 changes: 0 additions & 22 deletions test/accept_ack_protocol.erl

This file was deleted.

33 changes: 0 additions & 33 deletions test/acceptor_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit e92171a

Please sign in to comment.