aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2018-07-31 15:19:16 +0200
committerLoïc Hoguin <[email protected]>2018-07-31 15:19:16 +0200
commit265bc740d0abcddee8e7eef2286980f2db3088b0 (patch)
treea873353dd985a39f88f03cce8d036eabc03754b4
parentf854eb345f5cc5059e88cab860afa6ede8cfcafe (diff)
downloadranch-265bc740d0abcddee8e7eef2286980f2db3088b0.tar.gz
ranch-265bc740d0abcddee8e7eef2286980f2db3088b0.tar.bz2
ranch-265bc740d0abcddee8e7eef2286980f2db3088b0.zip
Revisit the manual pages for the various modules
-rw-r--r--doc/src/manual/ranch.asciidoc23
-rw-r--r--doc/src/manual/ranch_app.asciidoc3
-rw-r--r--doc/src/manual/ranch_protocol.asciidoc36
-rw-r--r--doc/src/manual/ranch_ssl.asciidoc278
-rw-r--r--doc/src/manual/ranch_tcp.asciidoc199
-rw-r--r--doc/src/manual/ranch_transport.asciidoc314
-rw-r--r--doc/src/manual/ranch_transport.sendfile.asciidoc84
7 files changed, 637 insertions, 300 deletions
diff --git a/doc/src/manual/ranch.asciidoc b/doc/src/manual/ranch.asciidoc
index f2cbb41..21a117e 100644
--- a/doc/src/manual/ranch.asciidoc
+++ b/doc/src/manual/ranch.asciidoc
@@ -104,20 +104,6 @@ options and socket options. Socket options may be given
directly (assuming they are not a map and no Ranch-specific
option needs to be given) or as part of `socket_opts`.
-The different options are described further down in this
-document.
-
-=== ref()
-
-[source,erlang]
-----
-ref() = any()
-----
-
-Unique name used to refer to a listener.
-
-== Option descriptions
-
None of the options are required.
ack_timeout::
@@ -160,6 +146,15 @@ socket_opts::
Socket options given to `Transport:listen/1`. Please refer to the
documentation of the transport module you are using for more details.
+=== ref()
+
+[source,erlang]
+----
+ref() = any()
+----
+
+Unique name used to refer to a listener.
+
== Changelog
* *1.6*: The `logger` option was added.
diff --git a/doc/src/manual/ranch_app.asciidoc b/doc/src/manual/ranch_app.asciidoc
index 5eca83a..c24a38c 100644
--- a/doc/src/manual/ranch_app.asciidoc
+++ b/doc/src/manual/ranch_app.asciidoc
@@ -19,6 +19,9 @@ service.
Functions:
* link:man:ranch(3)[ranch(3)] - Socket acceptor pool
+
+Transports:
+
* link:man:ranch_ssl(3)[ranch_ssl(3)] - SSL transport
* link:man:ranch_tcp(3)[ranch_tcp(3)] - TLS transport
diff --git a/doc/src/manual/ranch_protocol.asciidoc b/doc/src/manual/ranch_protocol.asciidoc
index 714a82b..8e8c0e0 100644
--- a/doc/src/manual/ranch_protocol.asciidoc
+++ b/doc/src/manual/ranch_protocol.asciidoc
@@ -2,27 +2,28 @@
== Name
-ranch_protocol - behaviour for protocol modules
+ranch_protocol - Protocol modules
== Description
-The `ranch_protocol` behaviour defines the interface used
+The module `ranch_protocol` defines the interface used
by Ranch protocols.
-== Types
-
-None.
-
== Callbacks
-=== start_link(Ref, Socket, Transport, ProtoOpts) -> {ok, pid()} | {ok, pid(), pid()}
+Ranch protocols implement the following interface:
-Ref = ranch:ref():: Listener name.
-Socket = any():: Socket for this connection.
-Transport = module():: Transport module for this socket.
-ProtoOpts = any():: Protocol options.
+[source,erlang]
+----
+start_link(Ref :: ranch:ref(),
+ _,
+ Transport :: module(),
+ ProtoOpts :: any())
+ -> {ok, ConnPid :: pid()}
+ | {ok, SupPid :: pid(), ConnPid :: pid()}
+----
-Start a new connection process for the given socket.
+Start a new connection process.
The only purpose of this callback is to start a process that
will handle the socket. It must spawn the process, link and
@@ -42,3 +43,14 @@ socket and assume no process has been started.
Do not perform any operations in this callback, as this would
block the supervisor responsible for starting connection
processes and degrade performance severely.
+
+== 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)].
+
+== See also
+
+link:man:ranch:handshake(3)[ranch:handshake(3)],
+link:man:ranch(7)[ranch(7)]
diff --git a/doc/src/manual/ranch_ssl.asciidoc b/doc/src/manual/ranch_ssl.asciidoc
index b809ec1..3a4a146 100644
--- a/doc/src/manual/ranch_ssl.asciidoc
+++ b/doc/src/manual/ranch_ssl.asciidoc
@@ -2,153 +2,261 @@
== Name
-ranch_ssl - SSL transport module
+ranch_ssl - SSL transport
== Description
-The `ranch_ssl` module implements an SSL Ranch transport.
+The module `ranch_ssl` implements an SSL Ranch transport.
+
+== Exports
+
+The module `ranch_ssl` implements the interface defined
+by link:man:ranch_transport(3)[ranch_transport(3)].
== Types
-=== ssl_opt()
+=== opt()
[source,erlang]
----
-ssl_opt() = {alpn_preferred_protocols, [binary()]}
- | {beast_mitigation, one_n_minus_one | zero_n | disabled}
- | {cacertfile, string()}
- | {cacerts, [public_key:der_encoded()]}
- | {cert, public_key:der_encoded()}
- | {certfile, string()}
- | {ciphers, [ssl:erl_cipher_suite()] | string()}
- | {client_renegotiation, boolean()}
- | {crl_cache, {module(), {internal | any(), list()}}}
- | {crl_check, boolean() | peer | best_effort}
- | {depth, 0..255}
- | {dh, public_key:der_encoded()}
- | {dhfile, string()}
- | {fail_if_no_peer_cert, boolean()}
- | {hibernate_after, integer() | undefined}
- | {honor_cipher_order, boolean()}
- | {key, {'RSAPrivateKey' | 'DSAPrivateKey' | 'PrivateKeyInfo', public_key:der_encoded()}}
- | {keyfile, string()}
- | {log_alert, boolean()}
- | {next_protocols_advertised, [binary()]}
- | {padding_check, boolean()}
- | {partial_chain, fun(([public_key:der_encoded()]) -> {trusted_ca, public_key:der_encoded()} | unknown_ca)}
- | {password, string()}
- | {psk_identity, string()}
- | {reuse_session, fun()}
- | {reuse_sessions, boolean()}
- | {secure_renegotiate, boolean()}
- | {signature_algs, [{atom(), atom()}]}
- | {sni_fun, fun()}
- | {sni_hosts, [{string(), ssl_opt()}]}
- | {user_lookup_fun, {fun(), any()}}
- | {v2_hello_compatible, boolean()}
- | {verify, ssl:verify_type()}
- | {verify_fun, {fun(), any()}}
- | {versions, [atom()]}.
+opt() :: ranch_tcp:opt() | ssl_opt()
----
-SSL-specific listen options.
+Listen options.
-=== opt() = ranch_tcp:opt() | ssl_opt()
+The TCP options are defined in link:man:ranch_tcp(3)[ranch_tcp(3)].
-Listen options.
+=== opts()
-=== opts() = [opt()]
+[source,erlang]
+----
+opts() :: [opt()]
+----
List of listen options.
-== Option descriptions
+=== ssl_opt()
+
+[source,erlang]
+----
+ssl_opt() = {alpn_preferred_protocols, [binary()]}
+ | {beast_mitigation, one_n_minus_one | zero_n | disabled}
+ | {cacertfile, string()}
+ | {cacerts, [public_key:der_encoded()]}
+ | {cert, public_key:der_encoded()}
+ | {certfile, string()}
+ | {ciphers, [ssl:erl_cipher_suite()] | string()}
+ | {client_renegotiation, boolean()}
+ | {crl_cache, {module(), {internal | any(), list()}}}
+ | {crl_check, boolean() | peer | best_effort}
+ | {depth, 0..255}
+ | {dh, public_key:der_encoded()}
+ | {dhfile, string()}
+ | {fail_if_no_peer_cert, boolean()}
+ | {hibernate_after, integer() | undefined}
+ | {honor_cipher_order, boolean()}
+ | {key, {'RSAPrivateKey' | 'DSAPrivateKey' | 'PrivateKeyInfo',
+ public_key:der_encoded()}}
+ | {keyfile, string()}
+ | {log_alert, boolean()}
+ | {next_protocols_advertised, [binary()]}
+ | {padding_check, boolean()}
+ | {partial_chain, fun(([public_key:der_encoded()])
+ -> {trusted_ca, public_key:der_encoded()} | unknown_ca)}
+ | {password, string()}
+ | {psk_identity, string()}
+ | {reuse_session, fun()}
+ | {reuse_sessions, boolean()}
+ | {secure_renegotiate, boolean()}
+ | {signature_algs, [{atom(), atom()}]}
+ | {sni_fun, fun()}
+ | {sni_hosts, [{string(), ssl_opt()}]}
+ | {user_lookup_fun, {fun(), any()}}
+ | {v2_hello_compatible, boolean()}
+ | {verify, ssl:verify_type()}
+ | {verify_fun, {fun(), any()}}
+ | {versions, [atom()]}
+----
+
+SSL-specific listen options.
Specifying a certificate is mandatory, either through the `cert`
-or the `certfile` option. None of the other options are required.
+or `certfile` option, or by configuring SNI. None of the other
+options are required.
-The default value is given next to the option name.
+The default value is given next to the option name:
alpn_preferred_protocols::
- Perform Application-Layer Protocol Negotiation with the given list of preferred protocols.
+
+Perform Application-Layer Protocol Negotiation
+with the given list of preferred protocols.
+
beast_mitigation::
- Change the BEAST mitigation strategy for SSL-3.0 and TLS-1.0 to interoperate with legacy software.
+
+Change the BEAST mitigation strategy for SSL-3.0 and TLS-1.0
+to interoperate with legacy software.
+
cacertfile::
- Path to PEM encoded trusted certificates file used to verify peer certificates.
+
+Path to PEM encoded trusted certificates file used to verify
+peer certificates.
+
cacerts::
- List of DER encoded trusted certificates.
+
+List of DER encoded trusted certificates.
+
cert::
- DER encoded user certificate.
+
+DER encoded user certificate.
+
certfile::
- Path to the PEM encoded user certificate file. May also contain the private key.
+
+Path to the PEM encoded user certificate file. May also
+contain the private key.
+
ciphers::
- List of ciphers that clients are allowed to use.
+
+List of ciphers that clients are allowed to use.
+
client_renegotiation (true)::
- Whether to allow client-initiated renegotiation.
+
+Whether to allow client-initiated renegotiation.
+
crl_cache ({ssl_crl_cache, {internal, []}})::
- Customize the module used to cache Certificate Revocation Lists.
+
+Customize the module used to cache Certificate Revocation Lists.
+
crl_check (false)::
- Whether to perform CRL check on all certificates in the chain during validation.
+
+Whether to perform CRL check on all certificates in the chain
+during validation.
+
depth (1)::
- Maximum of intermediate certificates allowed in the certification path.
+
+Maximum of intermediate certificates allowed in the
+certification path.
+
dh::
- DER encoded Diffie-Hellman parameters.
+
+DER encoded Diffie-Hellman parameters.
+
dhfile::
- Path to the PEM encoded Diffie-Hellman parameters file.
+
+Path to the PEM encoded Diffie-Hellman parameters file.
+
fail_if_no_peer_cert (false)::
- Whether to refuse the connection if the client sends an empty certificate.
+
+Whether to refuse the connection if the client sends an
+empty certificate.
+
hibernate_after (undefined)::
- Time in ms after which SSL socket processes go into hibernation to reduce memory usage.
+
+Time in ms after which SSL socket processes go into
+hibernation to reduce memory usage.
+
honor_cipher_order (false)::
- If true, use the server's preference for cipher selection. If false, use the client's preference.
+
+If true, use the server's preference for cipher selection.
+If false, use the client's preference.
+
key::
- DER encoded user private key.
+
+DER encoded user private key.
+
keyfile::
- Path to the PEM encoded private key file, if different than the certfile.
+
+Path to the PEM encoded private key file, if different from
+the certfile.
+
log_alert (true)::
- If false, error reports will not be displayed.
+
+If false, error reports will not be displayed.
+
next_protocols_advertised::
- List of protocols to send to the client if it supports the Next Protocol extension.
-nodelay (true)::
- Whether to enable TCP_NODELAY.
+
+List of protocols to send to the client if it supports the
+Next Protocol extension.
+
padding_check::
- Allow disabling the block cipher padding check for TLS-1.0 to be able to interoperate with legacy software.
+
+Allow disabling the block cipher padding check for TLS-1.0
+to be able to interoperate with legacy software.
+
partial_chain::
- Claim an intermediate CA in the chain as trusted.
+
+Claim an intermediate CA in the chain as trusted.
+
password::
- Password to the private key file, if password protected.
+
+Password to the private key file, if password protected.
+
psk_identity::
- Provide the given PSK identity hint to the client during the handshake.
+
+Provide the given PSK identity hint to the client during the
+handshake.
+
reuse_session::
- Custom policy to decide whether a session should be reused.
+
+Custom policy to decide whether a session should be reused.
+
reuse_sessions (false)::
- Whether to allow session reuse.
+
+Whether to allow session reuse.
+
secure_renegotiate (false)::
- Whether to reject renegotiation attempts that do not conform to RFC5746.
+
+Whether to reject renegotiation attempts that do not conform
+to RFC5746.
+
signature_algs::
- The TLS signature algorithm extension may be used, from TLS 1.2, to negotiate which signature algorithm to use during the TLS handshake.
+
+The TLS signature algorithm extension may be used, from TLS 1.2,
+to negotiate which signature algorithm to use during the TLS
+handshake.
+
sni_fun::
- Function called when the client requests a host using Server Name Indication. Returns options to apply.
+
+Function called when the client requests a host using Server
+Name Indication. Returns options to apply.
+
sni_hosts::
- Options to apply for the host that matches what the client requested with Server Name Indication.
+
+Options to apply for the host that matches what the client
+requested with Server Name Indication.
+
user_lookup_fun::
- Function called to determine the shared secret when using PSK, or provide parameters when using SRP.
+
+Function called to determine the shared secret when using PSK,
+or provide parameters when using SRP.
+
v2_hello_compatible::
- Accept clients that send hello messages in SSL-2.0 format while offering supported SSL/TLS versions.
+
+Accept clients that send hello messages in SSL-2.0 format while
+offering supported SSL/TLS versions.
+
verify (verify_none)::
- Use `verify_peer` to request a certificate from the client.
+
+Use `verify_peer` to request a certificate from the client.
+
verify_fun::
- Custom policy to decide whether a client certificate is valid.
+
+Custom policy to decide whether a client certificate is valid.
+
versions::
- TLS protocol versions that will be supported.
+
+TLS protocol versions that will be supported.
Note that the client will not send a certificate unless the
value for the `verify` option is set to `verify_peer`. This
-means that the `fail_if_no_peer_cert` only apply when combined
+means that `fail_if_no_peer_cert` only applies when combined
with the `verify` option. The `verify_fun` option allows
greater control over the client certificate validation.
The options `sni_fun` and `sni_hosts` are mutually exclusive.
-== Exports
+== See also
-None.
+link:man:ranch(7)[ranch(7)],
+link:man:ranch_transport(3)[ranch_transport(3)],
+link:man:ranch_tcp(3)[ranch_tcp(3)],
+ssl(3)
diff --git a/doc/src/manual/ranch_tcp.asciidoc b/doc/src/manual/ranch_tcp.asciidoc
index 6eb7fa3..d01b262 100644
--- a/doc/src/manual/ranch_tcp.asciidoc
+++ b/doc/src/manual/ranch_tcp.asciidoc
@@ -2,16 +2,19 @@
== Name
-ranch_tcp - TCP transport module
+ranch_tcp - TCP transport
== Description
-The `ranch_tcp` module implements a TCP Ranch transport.
+The module `ranch_tcp` implements a TCP Ranch transport.
-Note that due to bugs in OTP up to at least R16B02, it is
-recommended to disable async threads when using the
-`sendfile` function of this transport, as it can make
-the threads stuck indefinitely.
+The function `sendfile` may not work correctly when used
+against files stored in a VirtualBox shared folder.
+
+== Exports
+
+The module `ranch_tcp` implements the interface defined
+by link:man:ranch_transport(3)[ranch_transport(3)].
== Types
@@ -20,44 +23,36 @@ the threads stuck indefinitely.
[source,erlang]
----
opt() = {backlog, non_neg_integer()}
- | {buffer, non_neg_integer()}
- | {delay_send, boolean()}
- | {dontroute, boolean()}
- | {exit_on_close, boolean()}
- | {fd, non_neg_integer()}
- | {high_msgq_watermark, non_neg_integer()}
- | {high_watermark, non_neg_integer()}
- | inet
- | inet6
- | {ip, inet:ip_address()}
- | {ipv6_v6only, boolean()}
- | {keepalive, boolean()}
- | {linger, {boolean(), non_neg_integer()}}
- | {low_msgq_watermark, non_neg_integer()}
- | {low_watermark, non_neg_integer()}
- | {nodelay, boolean()}
- | {port, inet:port_number()}
- | {priority, integer()}
- | {raw, non_neg_integer(), non_neg_integer(), binary()}
- | {recbuf, non_neg_integer()}
- | {send_timeout, timeout()}
- | {send_timeout_close, boolean()}
- | {sndbuf, non_neg_integer()}
- | {tos, integer()}
+ | {buffer, non_neg_integer()}
+ | {delay_send, boolean()}
+ | {dontroute, boolean()}
+ | {exit_on_close, boolean()}
+ | {fd, non_neg_integer()}
+ | {high_msgq_watermark, non_neg_integer()}
+ | {high_watermark, non_neg_integer()}
+ | inet
+ | inet6
+ | {ip, inet:ip_address()}
+ | {ipv6_v6only, boolean()}
+ | {keepalive, boolean()}
+ | {linger, {boolean(), non_neg_integer()}}
+ | {low_msgq_watermark, non_neg_integer()}
+ | {low_watermark, non_neg_integer()}
+ | {nodelay, boolean()}
+ | {port, inet:port_number()}
+ | {priority, integer()}
+ | {raw, non_neg_integer(), non_neg_integer(), binary()}
+ | {recbuf, non_neg_integer()}
+ | {send_timeout, timeout()}
+ | {send_timeout_close, boolean()}
+ | {sndbuf, non_neg_integer()}
+ | {tos, integer()}
----
Listen options.
-This does not represent the entirety of the options that can
-be set on the socket, but only the options that may be
-set independently of protocol implementation.
-
-=== opts() = [opt()]
-
-List of listen options.
-
-Option descriptions
--------------------
+Note that additional options may be set by the protocol
+module using `Transport:setopts/2`.
None of the options are required.
@@ -65,62 +60,132 @@ Please consult the `gen_tcp` and `inet` manuals for a more
thorough description of these options. This manual only aims
to provide a short description along with what the defaults
are. Defaults may be different in Ranch compared to `gen_tcp`.
-Defaults are given next to the option name.
+Defaults are given next to the option name:
backlog (1024)::
- Max length of the queue of pending connections.
+
+Max length of the queue of pending connections.
+
buffer::
- Size of the buffer used by the Erlang driver. Default is system-dependent.
+
+Size of the buffer used by the Erlang driver. Default
+is system-dependent.
+
delay_send (false)::
- Always queue packets before sending, to send fewer, larger packets over the network.
+
+Always queue data before sending, to send fewer, larger
+packets over the network.
+
dontroute (false)::
- Don't send via a gateway, only send to directly connected hosts.
+
+Don't send via a gateway, only send to directly connected hosts.
+
exit_on_close (true)::
- Disable to allow sending data after a close has been detected.
+
+Disable to allow sending data after a close has been detected.
+
fd::
- File descriptor of the socket, if it was opened externally.
+
+File descriptor of the socket, if it was opened externally.
+
high_msgq_watermark (8192)::
- Limit in the amount of data in the socket message queue before the socket queue becomes busy.
+
+Limit in the amount of data in the socket message queue before
+the queue becomes busy.
+
high_watermark (8192)::
- Limit in the amount of data in the ERTS socket implementation's queue before the socket becomes busy.
+
+Limit in the amount of data in the ERTS socket implementation's
+queue before the socket becomes busy.
+
inet::
- Set up the socket for IPv4.
+
+Set up the socket for IPv4.
+
inet6::
- Set up the socket for IPv6.
+
+Set up the socket for IPv6.
+
ip::
- Interface to listen on. Listen on all interfaces by default.
+
+Interface to listen on. Listen on all interfaces by default.
+
ipv6_v6only (false)::
- Listen on IPv4 and IPv6 (false) or only on IPv6 (true). Use with inet6.
+
+Listen on IPv4 and IPv6 (false) or only on IPv6 (true).
+Use with inet6.
+
keepalive (false)::
- Enable sending of keep-alive messages.
+
+Enable sending of keep-alive messages.
+
linger ({false, 0})::
- Whether to wait and how long to flush data sent before closing the socket.
+
+Whether to wait and how long to flush data sent before closing
+the socket.
+
low_msgq_watermark (4096)::
- Amount of data in the socket message queue before the socket queue leaves busy state.
+
+Amount of data in the socket message queue before the queue
+leaves busy state.
+
low_watermark (4096)::
- Amount of data in the ERTS socket implementation's queue before the socket leaves busy state.
+
+Amount of data in the ERTS socket implementation's queue
+before the socket leaves busy state.
+
nodelay (true)::
- Whether to enable TCP_NODELAY.
+
+Whether to enable TCP_NODELAY.
+
port (0)::
- TCP port number to listen on. 0 means a random port will be used.
+
+TCP port number to listen on. 0 means a random port will be used.
+
priority (0)::
- Priority value for all packets to be sent by this socket.
+
+Priority value for all packets to be sent on this socket.
+
recbuf::
- Minimum size of the socket's receive buffer. Default is system-dependent.
+
+Minimum size of the socket's receive buffer.
+Default is system-dependent.
+
send_timeout (30000)::
- How long the send call may wait for confirmation before returning.
+
+How long the send call may wait for confirmation before returning.
+
send_timeout_close (true)::
- Whether to close the socket when the confirmation wasn't received.
+
+Whether to close the socket when the confirmation wasn't received.
+
sndbuf::
- Minimum size of the socket's send buffer. Default is system-dependent.
+
+Minimum size of the socket's send buffer.
+Default is system-dependent.
+
tos::
- Value for the IP_TOS IP level option. Use with caution.
+
+Value for the IP_TOS IP level option. Use with caution.
In addition, the `raw` option can be used to set system-specific
options by specifying the protocol level, the option number and
the actual option value specified as a binary. This option is not
portable. Use with caution.
-== Exports
+=== opts()
+
+[source,erlang]
+----
+opts() :: [opt()]
+----
+
+List of listen options.
+
+== See also
-None.
+link:man:ranch(7)[ranch(7)],
+link:man:ranch_transport(3)[ranch_transport(3)],
+link:man:ranch_ssl(3)[ranch_ssl(3)],
+gen_tcp(3),
+inet(3)
diff --git a/doc/src/manual/ranch_transport.asciidoc b/doc/src/manual/ranch_transport.asciidoc
index ec35589..50c0b0a 100644
--- a/doc/src/manual/ranch_transport.asciidoc
+++ b/doc/src/manual/ranch_transport.asciidoc
@@ -2,60 +2,90 @@
== Name
-ranch_transport - behaviour for transport modules
+ranch_transport - Transport modules
== Description
-The `ranch_transport` behaviour defines the interface used
+The module `ranch_transport` defines the interface used
by Ranch transports.
-== Types
+== Callbacks
-=== sendfile_opts() = [{chunk_size, non_neg_integer()}]
+Ranch transports implement the following interface:
-Options used by the sendfile function and callbacks.
+=== accept
-Allows configuring the chunk size, in bytes. Defaults to 8191 bytes.
+[source,erlang]
+----
+accept(LSocket :: socket(), Timeout :: timeout())
+ -> {ok, Socket :: socket()}
+ | {error, closed | timeout | atom()}
+----
-== Callbacks
+Use the listening socket returned by `listen/1`
+to accept a new connection. The timeout is specified
+in milliseconds.
+
+=== close
-=== accept(LSocket, Timeout) -> {ok, CSocket} | {error, closed | timeout | atom()}
+[source,erlang]
+----
+close(Socket :: socket()) -> ok
+----
-LSocket = CSocket = any():: Listening socket.
-Timeout = timeout():: Accept timeout.
+Close the socket.
-Accept a connection on the given listening socket.
+=== controlling_process
-The `handshake` callback will be used to initialize the socket
-after accepting the connection. This is most useful when the
-transport is not raw TCP, like with SSL for example.
+[source,erlang]
+----
+controlling_process(Socket :: socket(), Pid :: pid())
+ -> ok | {error, closed | not_owner | atom()}
+----
-=== close(Socket) -> ok
+Assign a new controlling process to the socket. The
+controlling process is the process that is linked to
+and receives messages from the socket.
-Socket = any():: Socket opened with listen/1 or accept/2.
+=== getopts
-Close the given socket.
+[source,erlang]
+----
+getopts(Socket :: socket(), SockOpts :: [atom()])
+ -> {ok, any()} | {error, atom()}
+----
-=== controlling_process(Socket, Pid) -> ok | {error, closed | not_owner | atom()}
+Get one or more options for the socket.
-Socket = any():: Socket opened with listen/1 or accept/2.
-Pid = pid():: Pid of the new owner of the socket.
+=== getstat
-Change the controlling process for the given socket.
+[source,erlang]
+----
+getstat(Socket :: socket())
+ -> {ok, SockStatValues :: any()} | {error, atom()}
+----
-The controlling process is the process that is allowed to
-perform operations on the socket, and that will receive
-messages from the socket when active mode is used. When
-the controlling process dies, the socket is closed.
+Get all statistics for the socket.
-=== handshake(CSocket0, Options, Timeout) -> {ok, CSocket1}
+[source,erlang]
+----
+getstat(Socket :: socket(), SockStats :: [atom()])
+ -> {ok, SockStatValues :: any()} | {error, atom()}
+----
-CSocket0 = any():: Uninitialized socket for this connection.
-Options = any():: Options for initialization.
-Timeout = timeout():: Handshake timeout.
-CSocket1 = any():: Initialized socket for this connection.
+Get one or more statistic options for the socket.
-Perform any necessary handshake for this transport.
+=== handshake
+
+[source,erlang]
+----
+handshake(Socket0 :: socket(),
+ SockOpts :: any(),
+ Timeout :: timeout())
+ -> {ok, Socket}
+----
+
+Perform the transport-level handshake.
This function will be called by connection processes
before performing any socket operation. It allows
@@ -67,158 +97,198 @@ from a transport to another depending on the capabilities
of the transports. For example a `ranch_tcp` socket may
be upgraded to a `ranch_ssl` one using this function.
-=== listen(TransOpts) -> {ok, LSocket} | {error, atom()}
-
-TransOpts = any():: Transport options.
-LSocket = any():: Listening socket.
+=== listen
-Listen for connections on the given port.
+[source,erlang]
+----
+listen(SockOpts :: any())
+ -> {ok, LSocket :: socket()} | {error, atom()}
+----
-The port is given as part of the transport options under
-the key `port`. Any other option is transport dependent.
+Create a socket that listens on the given port.
-The socket returned by this call can then be used to
-accept connections. It is not possible to send or receive
-data from the listening socket.
+The port may not be specified or may be set to 0, which
+means a random available port number will be chosen.
-=== messages() -> {OK, Closed, Error}
+=== messages
-OK = Closed = Error = atom():: Tuple names.
+[source,erlang]
+----
+messages()
+ -> {OK :: atom(),
+ Closed :: atom(),
+ Error :: atom()}
+----
-Return the atoms used to identify messages sent in active mode.
+Return the tuple keys for the messages sent by the socket.
-=== name() -> Name
+=== name
-Name = atom():: Transport module name.
+[source,erlang]
+----
+name() -> Name :: atom()
+----
Return the name of the transport.
-=== peername(CSocket) -> {ok, {IP, Port}} | {error, atom()}
+=== peername
-CSocket = any():: Socket for this connection.
-IP = inet:ip_address():: IP of the remote endpoint.
-Port = inet:port_number():: Port of the remote endpoint.
+[source,erlang]
+----
+peername(Socket :: socket())
+ -> {ok, {inet:ip_address(), inet:port_number()}}
+ | {error, atom()}.
+----
-Return the IP and port of the remote endpoint.
+Return the address and port number for the other end of
+the connection.
-=== recv(CSocket, Length, Timeout) -> {ok, Packet} | {error, closed | timeout | atom()}
+=== recv
-CSocket = any():: Socket for this connection.
-Length = non_neg_integer():: Requested length.
-Timeout = timeout():: Receive timeout.
-Packet = iodata() | any():: Data received.
+[source,erlang]
+----
+recv(Socket :: socket(),
+ Length :: non_neg_integer(),
+ Timeout :: timeout())
+ -> {ok, Packet :: any()}
+ | {error, closed | timeout | atom()}
+----
-Receive data from the given socket when in passive mode.
+Receive a packet from the socket in passive mode.
-Trying to receive data from a socket that is in active mode
-will return an error.
+Attempting to receive data from a socket that is
+in active mode will return an error.
-A length of 0 will return any data available on the socket.
+A length of 0 will return the data available on
+the socket as soon as possible, regardless of length.
While it is possible to use the timeout value `infinity`,
-this is highly discouraged as this could cause your process
+it is highly discouraged as it could cause your process
to get stuck waiting for data that will never come. This may
happen when a socket becomes half-open due to a crash of the
-remote endpoint. Wi-Fi going down is another common culprit
-of this issue.
+remote endpoint. Wi-Fi going down is another common culprit.
-=== send(CSocket, Packet) -> ok | {error, atom()}
+=== secure
-CSocket = any():: Socket for this connection.
-Packet = iodata():: Data to be sent.
+[source,erlang]
+----
+secure() -> boolean()
+----
-Send data to the given socket.
+Return whether the transport can be used for secure connections.
-=== sendfile(CSocket, File) -> sendfile(CSocket, File, 0, 0, [])
+=== send
-Alias of `ranch_transport:sendfile/5`.
+[source,erlang]
+----
+send(Socket :: socket(), Packet :: iodata())
+ -> ok | {error, atom()}
+----
-=== sendfile(CSocket, File, Offset, Bytes) -> sendfile(CSocket, File, Offset, Bytes, [])
+Send a packet on the socket.
-Alias of `ranch_transport:sendfile/5`.
+=== sendfile
-=== sendfile(CSocket, File, Offset, Bytes, SfOpts) -> {ok, SentBytes} | {error, atom()}
+[source,erlang]
+----
+sendfile(Socket, File)
+ -> sendfile(Socket, File, 0, 0, [])
-CSocket = any():: Socket for this connection.
-File = file:filename_all() | file:fd():: Filename or file descriptor for the file to be sent.
-Offset = non_neg_integer():: Begin sending at this position in the file.
-Bytes = non_neg_integer():: Send this many bytes.
-SentBytes = non_neg_integer():: This many bytes were sent.
-SfOpts = sendfile_opts():: Sendfile options.
+sendfile(Socket, File, Offset, Bytes)
+ -> sendfile(Socket, File, Offset, Bytes, [])
-Send data from a file to the given socket.
+sendfile(Socket :: socket(),
+ File :: file:name_all() | file:fd(),
+ Offset :: non_neg_integer(),
+ Bytes :: non_neg_integer(),
+ Opts :: sendfile_opts())
+ -> {ok, SentBytes :: non_neg_integer()} | {error, atom()}
+----
+
+Send a file on the socket.
The file may be sent full or in parts, and may be specified
by its filename or by an already open file descriptor.
Transports that manipulate TCP directly may use the
-`file:sendfile/{2,4,5}` function, which calls the sendfile
+`file:sendfile/2,4,5` function, which calls the `sendfile`
syscall where applicable (on Linux, for example). Other
transports can use the `sendfile/6` function exported from
this module.
-=== setopts(CSocket, SockOpts) -> ok | {error, atom()}
+=== setopts
+
+[source,erlang]
+----
+setopts(Socket :: socket(), SockOpts :: any())
+ -> ok | {error, atom()}
+----
+
+Set one or more options for the socket.
-CSocket = any():: Socket for this connection.
-SockOpts = any():: Socket options.
+=== shutdown
-Change options for the given socket.
+[source,erlang]
+----
+shutdown(Socket :: socket(),
+ How :: read | write | read_write)
+ -> ok | {error, atom()}
+----
-This is mainly useful for switching to active or passive mode
-or to set protocol-specific options.
+Close the socket for reading and/or writing.
-=== getopts(CSocket, SockOpts) -> {ok, SockOptValues} | {error, atom()}
+=== sockname
-CSocket = any():: Socket for this connection.
-SockOpts = [atom()]:: Socket option names.
-SockOptValues = list():: Socket options.
+[source,erlang]
+----
+sockname(Socket :: socket())
+ -> {ok, {inet:ip_address(), inet:port_number()}}
+ | {error, atom()}.
+----
-Get options for the given socket.
+Return the address and port number for the local end
+of the connection.
-=== getstat(CSocket) -> {ok, SockStatValues} | {error, atom()}
+== Exports
-CSocket = any():: Socket for this connection.
-SockStatValues = list():: Socket statistics.
+The following function can be used when implementing
+transport modules:
-Get statistics for the given socket.
+* link:man:ranch_transport:sendfile(3)[ranch_transport:sendfile(3)] - Send a file on the socket
-=== getstat(CSocket, SockStats) -> {ok, SockStatValues} | {error, atom()}
+== Types
-CSocket = any():: Socket for this connection.
-SockStats = [atom()]:: Socket statistic names.
-SockStatValues = list():: Socket statistics.
+=== sendfile_opts()
-Get statistics for the given socket.
+[source,erlang]
+----
+sendfile_opts() :: [{chunk_size, non_neg_integer()}]
+----
-=== shutdown(CSocket, How) -> ok | {error, atom()}
+Options accepted by the sendfile function and callbacks:
-CSocket = any():: Socket for this connection.
-How = read | write | read_write:: Which side(s) of the socket to close.
+chunk_size (8191)::
-Immediately close the socket in one or two directions.
+The chunk size, in bytes.
-=== sockname(Socket) -> {ok, {IP, Port}} | {error, atom()}
+=== socket()
-Socket = any():: Socket opened with listen/1 or accept/2.
-IP = inet:ip_address():: IP of the local endpoint.
-Port = inet:port_number():: Port of the local endpoint.
+[source,erlang]
+----
+socket() :: any()
+----
-Return the IP and port of the local endpoint.
+The socket.
-== Exports
+The exact type will vary depending on the transport module.
-=== sendfile(Transport, CSocket, File, Offset, Bytes, SfOpts) -> {ok, SentBytes} | {error, atom()}
+== Changelog
-Transport = module():: Transport module for this socket.
-CSocket = any():: Socket for this connection.
-File = file:filename_all() | file:fd():: Filename or file descriptor for the file to be sent.
-Offset = non_neg_integer():: Begin sending at this position in the file.
-Bytes = non_neg_integer():: Send this many bytes.
-SentBytes = non_neg_integer():: This many bytes were sent.
-SfOpts = sendfile_opts():: Sendfile options.
+* *1.6*: The `socket()` type was added for documentation purposes.
+* *1.6*: The type of the sendfile filename was extended.
-Send data from a file to the given socket.
+== See also
-This function emulates the function `file:sendfile/{2,4,5}`
-and may be used when transports are not manipulating TCP
-directly.
+link:man:ranch(7)[ranch(7)],
+link:man:ranch_tcp(3)[ranch_tcp(3)],
+link:man:ranch_ssl(3)[ranch_ssl(3)]
diff --git a/doc/src/manual/ranch_transport.sendfile.asciidoc b/doc/src/manual/ranch_transport.sendfile.asciidoc
new file mode 100644
index 0000000..1bbc79b
--- /dev/null
+++ b/doc/src/manual/ranch_transport.sendfile.asciidoc
@@ -0,0 +1,84 @@
+= ranch_transport:sendfile(3)
+
+== Name
+
+ranch_transport:sendfile - Send a file on the socket
+
+== Description
+
+[source,erlang]
+----
+sendfile(Transport :: module(),
+ Socket :: ranch_transport:socket(),
+ File :: file:name_all() | file:fd(),
+ Offset :: non_neg_integer(),
+ Bytes :: non_neg_integer(),
+ Opts :: ranch_transport:sendfile_opts())
+ -> {ok, SentBytes :: non_neg_integer()} | {error, atom()}
+----
+
+Send a file on the socket.
+
+The file may be sent full or in parts, and may be specified
+by its filename or by an already open file descriptor.
+
+This function emulates the function `file:sendfile/2,4,5`
+and may be used when transports are not manipulating TCP
+directly.
+
+== Arguments
+
+Transport::
+
+The transport module.
+
+Socket::
+
+The socket.
+
+File::
+
+The filename or file descriptor for the file to be sent.
+
+Offset::
+
+Start position in the file, in bytes.
+
+Bytes::
+
+Length in bytes.
+
+Opts::
+
+Additional options.
+
+== Return value
+
+The number of bytes actually sent is returned on success
+inside an `ok` tuple.
+
+An `error` tuple is returned otherwise.
+
+== Changelog
+
+* *1.6*: The type of the `File` argument was extended.
+
+== Examples
+
+.Implement Transport:sendfile using the fallback
+[source,erlang]
+----
+sendfile(Socket, Filename) ->
+ sendfile(Socket, Filename, 0, 0, []).
+
+sendfile(Socket, File, Offset, Bytes) ->
+ sendfile(Socket, File, Offset, Bytes, []).
+
+sendfile(Socket, File, Offset, Bytes, Opts) ->
+ ranch_transport:sendfile(?MODULE, Socket,
+ File, Offset, Bytes, Opts).
+----
+
+== See also
+
+link:man:ranch_transport(3)[ranch_transport(3)]