aboutsummaryrefslogtreecommitdiffstats
path: root/src/ranch_tcp.erl
diff options
context:
space:
mode:
authorjuhlig <[email protected]>2019-05-27 15:20:37 +0200
committerLoïc Hoguin <[email protected]>2019-05-27 16:03:29 +0200
commit30604262b5934b38e9f55f0d3ef44f8aed5310de (patch)
tree5a88a20152197921b266769684c17651afc44882 /src/ranch_tcp.erl
parentad82f58139ca88b7e82dcb6bd50063c899b685e9 (diff)
downloadranch-30604262b5934b38e9f55f0d3ef44f8aed5310de.tar.gz
ranch-30604262b5934b38e9f55f0d3ef44f8aed5310de.tar.bz2
ranch-30604262b5934b38e9f55f0d3ef44f8aed5310de.zip
Use transport options in ranch_transport:listen/1 callbacks
The callback `ranch_transport:listen/1` has changed to accept a map of transport options instead of socket options.
Diffstat (limited to 'src/ranch_tcp.erl')
-rw-r--r--src/ranch_tcp.erl18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/ranch_tcp.erl b/src/ranch_tcp.erl
index 764c4b8..3a6e4d9 100644
--- a/src/ranch_tcp.erl
+++ b/src/ranch_tcp.erl
@@ -78,17 +78,19 @@ secure() ->
messages() -> {tcp, tcp_closed, tcp_error, tcp_passive}.
--spec listen(opts()) -> {ok, inet:socket()} | {error, atom()}.
-listen(Opts) ->
- Opts2 = ranch:set_option_default(Opts, backlog, 1024),
- Opts3 = ranch:set_option_default(Opts2, nodelay, true),
- Opts4 = ranch:set_option_default(Opts3, send_timeout, 30000),
- Opts5 = ranch:set_option_default(Opts4, send_timeout_close, true),
+-spec listen(ranch:transport_opts(opts())) -> {ok, inet:socket()} | {error, atom()}.
+listen(TransOpts) ->
+ Logger = maps:get(logger, TransOpts, logger),
+ SocketOpts0 = maps:get(socket_opts, TransOpts, []),
+ SocketOpts1 = ranch:set_option_default(SocketOpts0, backlog, 1024),
+ SocketOpts2 = ranch:set_option_default(SocketOpts1, nodelay, true),
+ SocketOpts3 = ranch:set_option_default(SocketOpts2, send_timeout, 30000),
+ SocketOpts4 = ranch:set_option_default(SocketOpts3, send_timeout_close, true),
%% We set the port to 0 because it is given in the Opts directly.
%% The port in the options takes precedence over the one in the
%% first argument.
- gen_tcp:listen(0, ranch:filter_options(Opts5, disallowed_listen_options(),
- [binary, {active, false}, {packet, raw}, {reuseaddr, true}])).
+ gen_tcp:listen(0, ranch:filter_options(SocketOpts4, disallowed_listen_options(),
+ [binary, {active, false}, {packet, raw}, {reuseaddr, true}], Logger)).
%% 'binary' and 'list' are disallowed but they are handled
%% specifically as they do not have 2-tuple equivalents.