From 3ea575d8682560fc02d5583cbf2837e2f2f43e9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Thu, 9 May 2019 10:43:25 +0200 Subject: Remove Socket argument from ranch_protocol:start_link --- doc/src/guide/protocols.asciidoc | 8 ++++---- doc/src/manual/ranch.handshake.asciidoc | 5 ----- doc/src/manual/ranch_protocol.asciidoc | 8 ++++---- examples/tcp_echo/src/echo_protocol.erl | 4 ++-- examples/tcp_reverse/src/reverse_protocol.erl | 4 ++-- src/ranch_conns_sup.erl | 2 +- src/ranch_protocol.erl | 1 - test/active_echo_protocol.erl | 4 ++-- test/check_tcp_options.erl | 13 +++++++------ test/echo_protocol.erl | 4 ++-- test/notify_and_wait_protocol.erl | 4 ++-- test/proxy_protocol.erl | 4 ++-- test/remove_conn_and_wait_protocol.erl | 4 ++-- test/ssl_upgrade_protocol.erl | 4 ++-- test/supervisor_separate.erl | 6 +++--- test/transport_capabilities_protocol.erl | 4 ++-- test/trap_exit_protocol.erl | 4 ++-- 17 files changed, 39 insertions(+), 44 deletions(-) diff --git a/doc/src/guide/protocols.asciidoc b/doc/src/guide/protocols.asciidoc index 8f77ef4..89360ef 100644 --- a/doc/src/guide/protocols.asciidoc +++ b/doc/src/guide/protocols.asciidoc @@ -38,10 +38,10 @@ in `examples/tcp_echo/`. -module(echo_protocol). -behaviour(ranch_protocol). --export([start_link/4]). +-export([start_link/3]). -export([init/3]). -start_link(Ref, _Socket, Transport, Opts) -> +start_link(Ref, Transport, Opts) -> Pid = spawn_link(?MODULE, init, [Ref, Transport, Opts]), {ok, Pid}. @@ -80,11 +80,11 @@ the normal `gen_statem` execution loop. -behaviour(gen_statem). -behaviour(ranch_protocol). --export([start_link/4]). +-export([start_link/3]). -export([init/1]). %% Exports of other gen_statem callbacks here. -start_link(Ref, _Socket, Transport, Opts) -> +start_link(Ref, Transport, Opts) -> {ok, proc_lib:spawn_link(?MODULE, init, [{Ref, Transport, Opts}])}. init({Ref, Transport, _Opts = []}) -> diff --git a/doc/src/manual/ranch.handshake.asciidoc b/doc/src/manual/ranch.handshake.asciidoc index c8a6ee9..5d2694c 100644 --- a/doc/src/manual/ranch.handshake.asciidoc +++ b/doc/src/manual/ranch.handshake.asciidoc @@ -24,11 +24,6 @@ handshake necessary to give control of the socket to this process and also does the transport handshake, for example setting up the TLS connection. -Currently the socket can be obtained from a -`Protocol:start_link/4` argument and as a return value -from `ranch:handshake/1,2`. In Ranch 2.0 the socket will -only be available from `ranch:handshake/1,2`. - == Arguments Ref:: diff --git a/doc/src/manual/ranch_protocol.asciidoc b/doc/src/manual/ranch_protocol.asciidoc index 8e8c0e0..5a94399 100644 --- a/doc/src/manual/ranch_protocol.asciidoc +++ b/doc/src/manual/ranch_protocol.asciidoc @@ -16,7 +16,6 @@ Ranch protocols implement the following interface: [source,erlang] ---- start_link(Ref :: ranch:ref(), - _, Transport :: module(), ProtoOpts :: any()) -> {ok, ConnPid :: pid()} @@ -46,9 +45,10 @@ processes and degrade performance severely. == Changelog -* *1.6*: The second argument `Socket` was deprecated and will - be removed in Ranch 2.0. The socket should be obtained - by calling link:man:ranch:handshake(3)[ranch:handshake(3)]. +* *2.0*: The second argument `Socket` was removed. +* *1.6*: The second argument `Socket` was deprecated. Call + link:man:ranch:handshake(3)[ranch:handshake(3)] + to obtain the socket. == See also diff --git a/examples/tcp_echo/src/echo_protocol.erl b/examples/tcp_echo/src/echo_protocol.erl index d8944c6..c07b424 100644 --- a/examples/tcp_echo/src/echo_protocol.erl +++ b/examples/tcp_echo/src/echo_protocol.erl @@ -3,10 +3,10 @@ -module(echo_protocol). -behaviour(ranch_protocol). --export([start_link/4]). +-export([start_link/3]). -export([init/3]). -start_link(Ref, _Socket, Transport, Opts) -> +start_link(Ref, Transport, Opts) -> Pid = spawn_link(?MODULE, init, [Ref, Transport, Opts]), {ok, Pid}. diff --git a/examples/tcp_reverse/src/reverse_protocol.erl b/examples/tcp_reverse/src/reverse_protocol.erl index 91a5b95..2865a60 100644 --- a/examples/tcp_reverse/src/reverse_protocol.erl +++ b/examples/tcp_reverse/src/reverse_protocol.erl @@ -5,7 +5,7 @@ -behaviour(ranch_protocol). %% API. --export([start_link/4]). +-export([start_link/3]). %% gen_statem. -export([callback_mode/0]). @@ -20,7 +20,7 @@ %% API. -start_link(Ref, _Socket, Transport, Opts) -> +start_link(Ref, Transport, Opts) -> {ok, proc_lib:spawn_link(?MODULE, init, [{Ref, Transport, Opts}])}. %% gen_statem. diff --git a/src/ranch_conns_sup.erl b/src/ranch_conns_sup.erl index 171565e..70947e1 100644 --- a/src/ranch_conns_sup.erl +++ b/src/ranch_conns_sup.erl @@ -121,7 +121,7 @@ loop(State=#state{parent=Parent, ref=Ref, conn_type=ConnType, max_conns=MaxConns, logger=Logger}, CurConns, NbChildren, Sleepers) -> receive {?MODULE, start_protocol, To, Socket} -> - try Protocol:start_link(Ref, Socket, Transport, Opts) of + try Protocol:start_link(Ref, Transport, Opts) of {ok, Pid} -> handshake(State, CurConns, NbChildren, Sleepers, To, Socket, Pid, Pid); {ok, SupPid, ProtocolPid} when ConnType =:= supervisor -> diff --git a/src/ranch_protocol.erl b/src/ranch_protocol.erl index 30a5b51..5a93a65 100644 --- a/src/ranch_protocol.erl +++ b/src/ranch_protocol.erl @@ -17,7 +17,6 @@ %% Start a new connection process for the given socket. -callback start_link( Ref::ranch:ref(), - Socket::any(), Transport::module(), ProtocolOptions::any()) -> {ok, ConnectionPid::pid()} diff --git a/test/active_echo_protocol.erl b/test/active_echo_protocol.erl index 37dd6db..3c3ab0d 100644 --- a/test/active_echo_protocol.erl +++ b/test/active_echo_protocol.erl @@ -1,10 +1,10 @@ -module(active_echo_protocol). -behaviour(ranch_protocol). --export([start_link/4]). +-export([start_link/3]). -export([init/3]). -start_link(Ref, _Socket, Transport, Opts) -> +start_link(Ref, Transport, Opts) -> Pid = spawn_link(?MODULE, init, [Ref, Transport, Opts]), {ok, Pid}. diff --git a/test/check_tcp_options.erl b/test/check_tcp_options.erl index 18432ac..ecafef7 100644 --- a/test/check_tcp_options.erl +++ b/test/check_tcp_options.erl @@ -1,15 +1,16 @@ -module(check_tcp_options). -behaviour(ranch_protocol). --export([start_link/4]). +-export([start_link/3]). -export([init/3]). -start_link(_, Socket, _, [{pid, TestPid}|TcpOptions]) -> - {ok, RealTcpOptions} = - inet:getopts(Socket, [Key || {Key, _} <- TcpOptions]), - Pid = spawn_link(?MODULE, init, [TestPid, RealTcpOptions, TcpOptions]), +start_link(Ref, _, [{pid, TestPid}|TcpOptions]) -> + Pid = spawn_link(?MODULE, init, [Ref, TestPid, TcpOptions]), {ok, Pid}. -init(Pid, TcpOptions, TcpOptions) -> +init(Ref, Pid, TcpOptions) -> + {ok, Socket} = ranch:handshake(Ref), + {ok, RealTcpOptions} = inet:getopts(Socket, [Key || {Key, _} <- TcpOptions]), + true = TcpOptions =:= RealTcpOptions, Pid ! checked, receive after 2500 -> ok end. diff --git a/test/echo_protocol.erl b/test/echo_protocol.erl index 640f5c6..7bcf15a 100644 --- a/test/echo_protocol.erl +++ b/test/echo_protocol.erl @@ -1,10 +1,10 @@ -module(echo_protocol). -behaviour(ranch_protocol). --export([start_link/4]). +-export([start_link/3]). -export([init/3]). -start_link(Ref, _Socket, Transport, Opts) -> +start_link(Ref, Transport, Opts) -> Pid = spawn_link(?MODULE, init, [Ref, Transport, Opts]), {ok, Pid}. diff --git a/test/notify_and_wait_protocol.erl b/test/notify_and_wait_protocol.erl index f0136a1..e3e857b 100644 --- a/test/notify_and_wait_protocol.erl +++ b/test/notify_and_wait_protocol.erl @@ -1,10 +1,10 @@ -module(notify_and_wait_protocol). -behaviour(ranch_protocol). --export([start_link/4]). +-export([start_link/3]). -export([init/2]). -start_link(_, _, _, [{msg, Msg}, {pid, TestPid}]) -> +start_link(_, _, [{msg, Msg}, {pid, TestPid}]) -> Pid = spawn_link(?MODULE, init, [Msg, TestPid]), {ok, Pid}. diff --git a/test/proxy_protocol.erl b/test/proxy_protocol.erl index 9c679e3..88eb9ff 100644 --- a/test/proxy_protocol.erl +++ b/test/proxy_protocol.erl @@ -1,10 +1,10 @@ -module(proxy_protocol). -behaviour(ranch_protocol). --export([start_link/4]). +-export([start_link/3]). -export([init/3]). -start_link(Ref, _Socket, Transport, Opts) -> +start_link(Ref, Transport, Opts) -> Pid = spawn_link(?MODULE, init, [Ref, Transport, Opts]), {ok, Pid}. diff --git a/test/remove_conn_and_wait_protocol.erl b/test/remove_conn_and_wait_protocol.erl index caac41e..abb4281 100644 --- a/test/remove_conn_and_wait_protocol.erl +++ b/test/remove_conn_and_wait_protocol.erl @@ -1,10 +1,10 @@ -module(remove_conn_and_wait_protocol). -behaviour(ranch_protocol). --export([start_link/4]). +-export([start_link/3]). -export([init/3]). -start_link(Ref, _, _, [{remove, MaybeRemove, Timeout}]) -> +start_link(Ref, _, [{remove, MaybeRemove, Timeout}]) -> Pid = spawn_link(?MODULE, init, [Ref, MaybeRemove, Timeout]), {ok, Pid}. diff --git a/test/ssl_upgrade_protocol.erl b/test/ssl_upgrade_protocol.erl index cafbe13..67aec2b 100644 --- a/test/ssl_upgrade_protocol.erl +++ b/test/ssl_upgrade_protocol.erl @@ -1,10 +1,10 @@ -module(ssl_upgrade_protocol). -behaviour(ranch_protocol). --export([start_link/4]). +-export([start_link/3]). -export([init/3]). -start_link(Ref, _Socket, Transport, Opts) -> +start_link(Ref, Transport, Opts) -> Pid = spawn_link(?MODULE, init, [Ref, Transport, Opts]), {ok, Pid}. diff --git a/test/supervisor_separate.erl b/test/supervisor_separate.erl index 5f1f326..f96c7e4 100644 --- a/test/supervisor_separate.erl +++ b/test/supervisor_separate.erl @@ -2,13 +2,13 @@ -behavior(supervisor). -behavior(ranch_protocol). --export([start_link/4]). +-export([start_link/3]). -export([init/1]). -start_link(Ref, Socket, Transport, Opts) -> +start_link(Ref, Transport, Opts) -> {ok, SupPid} = supervisor:start_link(?MODULE, []), {ok, ConnPid} = supervisor:start_child(SupPid, - {echo_protocol, {echo_protocol, start_link, [Ref, Socket, Transport, Opts]}, + {echo_protocol, {echo_protocol, start_link, [Ref, Transport, Opts]}, temporary, 5000, worker, [echo_protocol]}), {ok, SupPid, ConnPid}. diff --git a/test/transport_capabilities_protocol.erl b/test/transport_capabilities_protocol.erl index ba5024a..5f23d39 100644 --- a/test/transport_capabilities_protocol.erl +++ b/test/transport_capabilities_protocol.erl @@ -1,10 +1,10 @@ -module(transport_capabilities_protocol). -behaviour(ranch_protocol). --export([start_link/4]). +-export([start_link/3]). -export([init/3]). -start_link(Ref, _Socket, Transport, Opts) -> +start_link(Ref, Transport, Opts) -> Pid = spawn_link(?MODULE, init, [Ref, Transport, Opts]), {ok, Pid}. diff --git a/test/trap_exit_protocol.erl b/test/trap_exit_protocol.erl index 6100075..da71fb4 100644 --- a/test/trap_exit_protocol.erl +++ b/test/trap_exit_protocol.erl @@ -1,10 +1,10 @@ -module(trap_exit_protocol). -behaviour(ranch_protocol). --export([start_link/4]). +-export([start_link/3]). -export([init/3]). -start_link(Ref, _Socket, Transport, Opts) -> +start_link(Ref, Transport, Opts) -> Pid = spawn_link(?MODULE, init, [Ref, Transport, Opts]), {ok, Pid}. -- cgit v1.2.3