Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add the {nodelay, boolean()} option controlling TCP_NODELAY

Enabled by default.

A comprehensive explanation about TCP_NODELAY and the Nagle algorithm
can be found at http://www.stuartcheshire.org/papers/NagleDelayedAck/
  • Loading branch information...
commit cd099983b1b807b87fa050d1e4ff0a13aba25b49 1 parent de9b6f7
Loïc Hoguin essen authored
Showing with 12 additions and 7 deletions.
  1. +7 −4 src/ranch_ssl.erl
  2. +5 −3 src/ranch_tcp.erl
11 src/ranch_ssl.erl
View
@@ -64,6 +64,7 @@ messages() -> {ssl, ssl_closed, ssl_error}.
%% by default.</dd>
%% <dt>keyfile</dt><dd>Optional. Path to the file containing the user's
%% private PEM encoded key.</dd>
+%% <dt>nodelay</dt><dd>Optional. Enable TCP_NODELAY. Enabled by default.</dd>
%% <dt>password</dt><dd>Optional. String containing the user's password.
%% All private keyfiles must be password protected currently.</dd>
%% <dt>port</dt><dd>TCP port number to open. Defaults to 0 (see below)</dd>
@@ -78,8 +79,8 @@ messages() -> {ssl, ssl_closed, ssl_error}.
%% @see ssl:listen/2
-spec listen([{backlog, non_neg_integer()} | {cacertfile, string()}
| {certfile, string()} | {ciphers, [ssl:erl_cipher_suite()] | string()}
- | {ip, inet:ip_address()} | {keyfile, string()} | {password, string()}
- | {port, inet:port_number()}])
+ | {ip, inet:ip_address()} | {keyfile, string()} | {nodelay, boolean()}
+ | {password, string()} | {port, inet:port_number()}])
-> {ok, ssl:sslsocket()} | {error, atom()}.
listen(Opts) ->
ranch:require([crypto, public_key, ssl]),
@@ -89,8 +90,10 @@ listen(Opts) ->
%% The port in the options takes precedence over the one in the
%% first argument.
ssl:listen(0, ranch:filter_options(Opts2,
- [backlog, cacertfile, certfile, ciphers, ip, keyfile, password, port],
- [binary, {active, false}, {packet, raw}, {reuseaddr, true}])).
+ [backlog, cacertfile, certfile, ciphers, ip,
+ keyfile, nodelay, password, port],
+ [binary, {active, false}, {packet, raw},
+ {reuseaddr, true}, {nodelay, true}])).
%% @doc Accept connections with the given listening socket.
%%
8 src/ranch_tcp.erl
View
@@ -50,6 +50,7 @@ messages() -> {tcp, tcp_closed, tcp_error}.
%% Defaults to 1024.</dd>
%% <dt>ip</dt><dd>Interface to listen on. Listen on all interfaces
%% by default.</dd>
+%% <dt>nodelay</dt><dd>Optional. Enable TCP_NODELAY. Enabled by default.</dd>
%% <dt>port</dt><dd>TCP port number to open. Defaults to 0 (see below).</dd>
%% </dl>
%%
@@ -61,15 +62,16 @@ messages() -> {tcp, tcp_closed, tcp_error}.
%%
%% @see gen_tcp:listen/2
-spec listen([{backlog, non_neg_integer()} | {ip, inet:ip_address()}
- | {port, inet:port_number()}])
+ | {nodelay, boolean()} | {port, inet:port_number()}])
-> {ok, inet:socket()} | {error, atom()}.
listen(Opts) ->
Opts2 = ranch:set_option_default(Opts, backlog, 1024),
%% 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(Opts2, [port, ip, backlog],
- [binary, {active, false}, {packet, raw}, {reuseaddr, true}])).
+ gen_tcp:listen(0, ranch:filter_options(Opts2, [backlog, ip, nodelay, port],
+ [binary, {active, false}, {packet, raw},
+ {reuseaddr, true}, {nodelay, true}])).
%% @doc Accept connections with the given listening socket.
%% @see gen_tcp:accept/2
Please sign in to comment.
Something went wrong with that request. Please try again.