aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Köhler <andreas.koehler@1und1.de>2010-11-08 13:46:56 +0100
committerBadlop <badlop@process-one.net>2010-11-10 23:45:27 +0100
commitd8d20d5b88382122c0017e348bdb9e29989c86df (patch)
tree8fc8d467b969b5e1b66b4bd7525351276aace365
parentBind listener ports early and start accepting connections later (diff)
Before binding tcp ports, checks the socket type and listener options
(EJAB-1334) If the callback module has a socket type of independent and needs to create the listener itself, do not pre-bind the port. The same holds if there are errors in the listener configuration.
-rw-r--r--src/ejabberd_listener.erl27
1 files changed, 19 insertions, 8 deletions
diff --git a/src/ejabberd_listener.erl b/src/ejabberd_listener.erl
index dbe4d292e..2553c8da3 100644
--- a/src/ejabberd_listener.erl
+++ b/src/ejabberd_listener.erl
@@ -60,18 +60,29 @@ bind_tcp_ports() ->
Ls ->
lists:foreach(
fun({Port, Module, Opts}) ->
- bind_tcp_port(Port, Module, Opts)
+ ModuleRaw = strip_frontend(Module),
+ case ModuleRaw:socket_type() of
+ independent -> ok;
+ _ ->
+ bind_tcp_port(Port, Module, Opts)
+ end
end, Ls)
end.
bind_tcp_port(PortIP, Module, RawOpts) ->
- {Port, IPT, IPS, IPV, Proto, OptsClean} = parse_listener_portip(PortIP, RawOpts),
- {_Opts, SockOpts} = prepare_opts(IPT, IPV, OptsClean),
- case Proto of
- udp -> ok;
- _ ->
- ListenSocket = listen_tcp(PortIP, Module, SockOpts, Port, IPS),
- ets:insert(listen_sockets, {PortIP, ListenSocket})
+ try check_listener_options(RawOpts) of
+ ok ->
+ {Port, IPT, IPS, IPV, Proto, OptsClean} = parse_listener_portip(PortIP, RawOpts),
+ {_Opts, SockOpts} = prepare_opts(IPT, IPV, OptsClean),
+ case Proto of
+ udp -> ok;
+ _ ->
+ ListenSocket = listen_tcp(PortIP, Module, SockOpts, Port, IPS),
+ ets:insert(listen_sockets, {PortIP, ListenSocket})
+ end
+ catch
+ throw:{error, Error} ->
+ ?ERROR_MSG(Error, [])
end.
start_listeners() ->