Browse Source

Remove Socket argument from ranch_protocol:start_link

Loïc Hoguin 6 years ago
parent
commit
3ea575d868

+ 4 - 4
doc/src/guide/protocols.asciidoc

@@ -38,10 +38,10 @@ in `examples/tcp_echo/`.
 -module(echo_protocol).
 -module(echo_protocol).
 -behaviour(ranch_protocol).
 -behaviour(ranch_protocol).
 
 
--export([start_link/4]).
+-export([start_link/3]).
 -export([init/3]).
 -export([init/3]).
 
 
-start_link(Ref, _Socket, Transport, Opts) ->
+start_link(Ref, Transport, Opts) ->
 	Pid = spawn_link(?MODULE, init, [Ref, Transport, Opts]),
 	Pid = spawn_link(?MODULE, init, [Ref, Transport, Opts]),
 	{ok, Pid}.
 	{ok, Pid}.
 
 
@@ -80,11 +80,11 @@ the normal `gen_statem` execution loop.
 -behaviour(gen_statem).
 -behaviour(gen_statem).
 -behaviour(ranch_protocol).
 -behaviour(ranch_protocol).
 
 
--export([start_link/4]).
+-export([start_link/3]).
 -export([init/1]).
 -export([init/1]).
 %% Exports of other gen_statem callbacks here.
 %% 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}])}.
 	{ok, proc_lib:spawn_link(?MODULE, init, [{Ref, Transport, Opts}])}.
 
 
 init({Ref, Transport, _Opts = []}) ->
 init({Ref, Transport, _Opts = []}) ->

+ 0 - 5
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
 process and also does the transport handshake, for example
 setting up the TLS connection.
 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
 == Arguments
 
 
 Ref::
 Ref::

+ 4 - 4
doc/src/manual/ranch_protocol.asciidoc

@@ -16,7 +16,6 @@ Ranch protocols implement the following interface:
 [source,erlang]
 [source,erlang]
 ----
 ----
 start_link(Ref       :: ranch:ref(),
 start_link(Ref       :: ranch:ref(),
-           _,
            Transport :: module(),
            Transport :: module(),
            ProtoOpts :: any())
            ProtoOpts :: any())
     -> {ok, ConnPid :: pid()}
     -> {ok, ConnPid :: pid()}
@@ -46,9 +45,10 @@ processes and degrade performance severely.
 
 
 == Changelog
 == 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
 == See also
 
 

+ 2 - 2
examples/tcp_echo/src/echo_protocol.erl

@@ -3,10 +3,10 @@
 -module(echo_protocol).
 -module(echo_protocol).
 -behaviour(ranch_protocol).
 -behaviour(ranch_protocol).
 
 
--export([start_link/4]).
+-export([start_link/3]).
 -export([init/3]).
 -export([init/3]).
 
 
-start_link(Ref, _Socket, Transport, Opts) ->
+start_link(Ref, Transport, Opts) ->
 	Pid = spawn_link(?MODULE, init, [Ref, Transport, Opts]),
 	Pid = spawn_link(?MODULE, init, [Ref, Transport, Opts]),
 	{ok, Pid}.
 	{ok, Pid}.
 
 

+ 2 - 2
examples/tcp_reverse/src/reverse_protocol.erl

@@ -5,7 +5,7 @@
 -behaviour(ranch_protocol).
 -behaviour(ranch_protocol).
 
 
 %% API.
 %% API.
--export([start_link/4]).
+-export([start_link/3]).
 
 
 %% gen_statem.
 %% gen_statem.
 -export([callback_mode/0]).
 -export([callback_mode/0]).
@@ -20,7 +20,7 @@
 
 
 %% API.
 %% API.
 
 
-start_link(Ref, _Socket, Transport, Opts) ->
+start_link(Ref, Transport, Opts) ->
 	{ok, proc_lib:spawn_link(?MODULE, init, [{Ref, Transport, Opts}])}.
 	{ok, proc_lib:spawn_link(?MODULE, init, [{Ref, Transport, Opts}])}.
 
 
 %% gen_statem.
 %% gen_statem.

+ 1 - 1
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) ->
 		max_conns=MaxConns, logger=Logger}, CurConns, NbChildren, Sleepers) ->
 	receive
 	receive
 		{?MODULE, start_protocol, To, Socket} ->
 		{?MODULE, start_protocol, To, Socket} ->
-			try Protocol:start_link(Ref, Socket, Transport, Opts) of
+			try Protocol:start_link(Ref, Transport, Opts) of
 				{ok, Pid} ->
 				{ok, Pid} ->
 					handshake(State, CurConns, NbChildren, Sleepers, To, Socket, Pid, Pid);
 					handshake(State, CurConns, NbChildren, Sleepers, To, Socket, Pid, Pid);
 				{ok, SupPid, ProtocolPid} when ConnType =:= supervisor ->
 				{ok, SupPid, ProtocolPid} when ConnType =:= supervisor ->

+ 0 - 1
src/ranch_protocol.erl

@@ -17,7 +17,6 @@
 %% Start a new connection process for the given socket.
 %% Start a new connection process for the given socket.
 -callback start_link(
 -callback start_link(
 		Ref::ranch:ref(),
 		Ref::ranch:ref(),
-		Socket::any(),
 		Transport::module(),
 		Transport::module(),
 		ProtocolOptions::any())
 		ProtocolOptions::any())
 	-> {ok, ConnectionPid::pid()}
 	-> {ok, ConnectionPid::pid()}

+ 2 - 2
test/active_echo_protocol.erl

@@ -1,10 +1,10 @@
 -module(active_echo_protocol).
 -module(active_echo_protocol).
 -behaviour(ranch_protocol).
 -behaviour(ranch_protocol).
 
 
--export([start_link/4]).
+-export([start_link/3]).
 -export([init/3]).
 -export([init/3]).
 
 
-start_link(Ref, _Socket, Transport, Opts) ->
+start_link(Ref, Transport, Opts) ->
 	Pid = spawn_link(?MODULE, init, [Ref, Transport, Opts]),
 	Pid = spawn_link(?MODULE, init, [Ref, Transport, Opts]),
 	{ok, Pid}.
 	{ok, Pid}.
 
 

+ 7 - 6
test/check_tcp_options.erl

@@ -1,15 +1,16 @@
 -module(check_tcp_options).
 -module(check_tcp_options).
 -behaviour(ranch_protocol).
 -behaviour(ranch_protocol).
 
 
--export([start_link/4]).
+-export([start_link/3]).
 -export([init/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}.
 	{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,
 	Pid ! checked,
 	receive after 2500 -> ok end.
 	receive after 2500 -> ok end.

+ 2 - 2
test/echo_protocol.erl

@@ -1,10 +1,10 @@
 -module(echo_protocol).
 -module(echo_protocol).
 -behaviour(ranch_protocol).
 -behaviour(ranch_protocol).
 
 
--export([start_link/4]).
+-export([start_link/3]).
 -export([init/3]).
 -export([init/3]).
 
 
-start_link(Ref, _Socket, Transport, Opts) ->
+start_link(Ref, Transport, Opts) ->
 	Pid = spawn_link(?MODULE, init, [Ref, Transport, Opts]),
 	Pid = spawn_link(?MODULE, init, [Ref, Transport, Opts]),
 	{ok, Pid}.
 	{ok, Pid}.
 
 

+ 2 - 2
test/notify_and_wait_protocol.erl

@@ -1,10 +1,10 @@
 -module(notify_and_wait_protocol).
 -module(notify_and_wait_protocol).
 -behaviour(ranch_protocol).
 -behaviour(ranch_protocol).
 
 
--export([start_link/4]).
+-export([start_link/3]).
 -export([init/2]).
 -export([init/2]).
 
 
-start_link(_, _, _, [{msg, Msg}, {pid, TestPid}]) ->
+start_link(_, _, [{msg, Msg}, {pid, TestPid}]) ->
 	Pid = spawn_link(?MODULE, init, [Msg, TestPid]),
 	Pid = spawn_link(?MODULE, init, [Msg, TestPid]),
 	{ok, Pid}.
 	{ok, Pid}.
 
 

+ 2 - 2
test/proxy_protocol.erl

@@ -1,10 +1,10 @@
 -module(proxy_protocol).
 -module(proxy_protocol).
 -behaviour(ranch_protocol).
 -behaviour(ranch_protocol).
 
 
--export([start_link/4]).
+-export([start_link/3]).
 -export([init/3]).
 -export([init/3]).
 
 
-start_link(Ref, _Socket, Transport, Opts) ->
+start_link(Ref, Transport, Opts) ->
 	Pid = spawn_link(?MODULE, init, [Ref, Transport, Opts]),
 	Pid = spawn_link(?MODULE, init, [Ref, Transport, Opts]),
 	{ok, Pid}.
 	{ok, Pid}.
 
 

+ 2 - 2
test/remove_conn_and_wait_protocol.erl

@@ -1,10 +1,10 @@
 -module(remove_conn_and_wait_protocol).
 -module(remove_conn_and_wait_protocol).
 -behaviour(ranch_protocol).
 -behaviour(ranch_protocol).
 
 
--export([start_link/4]).
+-export([start_link/3]).
 -export([init/3]).
 -export([init/3]).
 
 
-start_link(Ref, _, _, [{remove, MaybeRemove, Timeout}]) ->
+start_link(Ref, _, [{remove, MaybeRemove, Timeout}]) ->
 	Pid = spawn_link(?MODULE, init, [Ref, MaybeRemove, Timeout]),
 	Pid = spawn_link(?MODULE, init, [Ref, MaybeRemove, Timeout]),
 	{ok, Pid}.
 	{ok, Pid}.
 
 

+ 2 - 2
test/ssl_upgrade_protocol.erl

@@ -1,10 +1,10 @@
 -module(ssl_upgrade_protocol).
 -module(ssl_upgrade_protocol).
 -behaviour(ranch_protocol).
 -behaviour(ranch_protocol).
 
 
--export([start_link/4]).
+-export([start_link/3]).
 -export([init/3]).
 -export([init/3]).
 
 
-start_link(Ref, _Socket, Transport, Opts) ->
+start_link(Ref, Transport, Opts) ->
 	Pid = spawn_link(?MODULE, init, [Ref, Transport, Opts]),
 	Pid = spawn_link(?MODULE, init, [Ref, Transport, Opts]),
 	{ok, Pid}.
 	{ok, Pid}.
 
 

+ 3 - 3
test/supervisor_separate.erl

@@ -2,13 +2,13 @@
 -behavior(supervisor).
 -behavior(supervisor).
 -behavior(ranch_protocol).
 -behavior(ranch_protocol).
 
 
--export([start_link/4]).
+-export([start_link/3]).
 -export([init/1]).
 -export([init/1]).
 
 
-start_link(Ref, Socket, Transport, Opts) ->
+start_link(Ref, Transport, Opts) ->
 	{ok, SupPid} = supervisor:start_link(?MODULE, []),
 	{ok, SupPid} = supervisor:start_link(?MODULE, []),
 	{ok, ConnPid} = supervisor:start_child(SupPid,
 	{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]}),
 			temporary, 5000, worker, [echo_protocol]}),
 	{ok, SupPid, ConnPid}.
 	{ok, SupPid, ConnPid}.
 
 

+ 2 - 2
test/transport_capabilities_protocol.erl

@@ -1,10 +1,10 @@
 -module(transport_capabilities_protocol).
 -module(transport_capabilities_protocol).
 -behaviour(ranch_protocol).
 -behaviour(ranch_protocol).
 
 
--export([start_link/4]).
+-export([start_link/3]).
 -export([init/3]).
 -export([init/3]).
 
 
-start_link(Ref, _Socket, Transport, Opts) ->
+start_link(Ref, Transport, Opts) ->
 	Pid = spawn_link(?MODULE, init, [Ref, Transport, Opts]),
 	Pid = spawn_link(?MODULE, init, [Ref, Transport, Opts]),
 	{ok, Pid}.
 	{ok, Pid}.
 
 

+ 2 - 2
test/trap_exit_protocol.erl

@@ -1,10 +1,10 @@
 -module(trap_exit_protocol).
 -module(trap_exit_protocol).
 -behaviour(ranch_protocol).
 -behaviour(ranch_protocol).
 
 
--export([start_link/4]).
+-export([start_link/3]).
 -export([init/3]).
 -export([init/3]).
 
 
-start_link(Ref, _Socket, Transport, Opts) ->
+start_link(Ref, Transport, Opts) ->
 	Pid = spawn_link(?MODULE, init, [Ref, Transport, Opts]),
 	Pid = spawn_link(?MODULE, init, [Ref, Transport, Opts]),
 	{ok, Pid}.
 	{ok, Pid}.