aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ranch.erl17
-rw-r--r--src/ranch_acceptors_sup.erl8
2 files changed, 22 insertions, 3 deletions
diff --git a/src/ranch.erl b/src/ranch.erl
index 6d1d5e8..0924ee7 100644
--- a/src/ranch.erl
+++ b/src/ranch.erl
@@ -59,8 +59,21 @@ start_listener(Ref, NbAcceptors, Transport, TransOpts, Protocol, ProtoOpts)
false ->
{error, badarg};
true ->
- supervisor:start_child(ranch_sup, child_spec(Ref, NbAcceptors,
- Transport, TransOpts, Protocol, ProtoOpts))
+ Res = supervisor:start_child(ranch_sup, child_spec(Ref, NbAcceptors,
+ Transport, TransOpts, Protocol, ProtoOpts)),
+ case proplists:get_value(socket, TransOpts) of
+ undefined ->
+ ok;
+ Socket ->
+ %% change the controlling process so the caller dying doesn't
+ %% close the port
+ ListenerPid = ranch_server:lookup_listener(Ref),
+ %%% Note: the catch is here because SSL crashes when you change
+ %%% the controlling process of a listen socket because of a bug.
+ %%% The bug will be fixed in R16.
+ catch(Transport:controlling_process(Socket, ListenerPid))
+ end,
+ Res
end.
%% @doc Stop a listener identified by <em>Ref</em>.
diff --git a/src/ranch_acceptors_sup.erl b/src/ranch_acceptors_sup.erl
index 2e45acf..1d9503c 100644
--- a/src/ranch_acceptors_sup.erl
+++ b/src/ranch_acceptors_sup.erl
@@ -35,7 +35,13 @@ start_link(Ref, NbAcceptors, Transport, TransOpts,
init([Ref, NbAcceptors, Transport, TransOpts,
Protocol, ListenerPid, ConnsPid]) ->
- {ok, LSocket} = Transport:listen(TransOpts),
+ LSocket = case proplists:get_value(socket, TransOpts) of
+ undefined ->
+ {ok, Socket} = Transport:listen(TransOpts),
+ Socket;
+ Socket ->
+ Socket
+ end,
{ok, {_, Port}} = Transport:sockname(LSocket),
ranch_listener:set_port(ListenerPid, Port),
Procs = [