Module ranch_tcp

TCP transport API.

Behaviours: ranch_transport.

See also: gen_tcp.

Description

TCP transport API.

Wrapper around gen_tcp implementing the Ranch transport API.

Data Types

opts()

opts() = [{backlog, non_neg_integer()} | {ip, inet:ip_address()} | {nodelay, boolean()} | {port, inet:port_number()} | {raw, non_neg_integer(), non_neg_integer(), non_neg_integer() | binary()}]

Function Index

accept/2Accept connections with the given listening socket.
close/1Close the given socket.
controlling_process/2Give control of the socket to a new process.
listen/1Listen for connections on the given port number.
messages/0Atoms used to identify messages in {active, once | true} mode.
name/0Name of this transport, tcp.
peername/1Return the remote address and port of the connection.
recv/3Receive data from a socket in passive mode.
send/2Send data on a socket.
sendfile/2Equivalent to sendfile(Socket, File, Offset, Bytes, []).
sendfile/4Equivalent to sendfile(Socket, File, Offset, Bytes, []).
sendfile/5Send part of a file on a socket.
setopts/2Set options on the given socket.
sockname/1Return the local address and port of the connection.

Function Details

accept/2

accept(LSocket::inet:socket(), Timeout::timeout()) -> {ok, inet:socket()} | {error, closed | timeout | atom()}

Accept connections with the given listening socket.

See also: gen_tcp:accept/2.

close/1

close(Socket::inet:socket()) -> ok

Close the given socket.

See also: gen_tcp:close/1.

controlling_process/2

controlling_process(Socket::inet:socket(), Pid::pid()) -> ok | {error, closed | not_owner | atom()}

Give control of the socket to a new process.

Must be called from the process currently controlling the socket, otherwise an {error, not_owner} tuple will be returned.

See also: gen_tcp:controlling_process/2.

listen/1

listen(Opts::opts()) -> {ok, inet:socket()} | {error, atom()}

Listen for connections on the given port number.

Calling this function returns a listening socket that can then be passed to accept/2 to accept connections.

The available options are:
backlog
Maximum length of the pending connections queue. Defaults to 1024.
ip
Interface to listen on. Listen on all interfaces by default.
nodelay
Optional. Enable TCP_NODELAY. Enabled by default.
port
TCP port number to open. Defaults to 0 (see below).
You can listen to a random port by setting the port option to 0. It is then possible to retrieve this port number by calling sockname/1 on the listening socket. If you are using Ranch's listener API, then this port number can obtained through ranch:get_port/1 instead.

See also: gen_tcp:listen/2.

messages/0

messages() -> any()

Atoms used to identify messages in {active, once | true} mode.

name/0

name() -> any()

Name of this transport, tcp.

peername/1

peername(Socket::inet:socket()) -> {ok, {inet:ip_address(), inet:port_number()}} | {error, atom()}

Return the remote address and port of the connection.

See also: inet:peername/1.

recv/3

recv(Socket::inet:socket(), Length::non_neg_integer(), Timeout::timeout()) -> {ok, any()} | {error, closed | atom()}

Receive data from a socket in passive mode.

See also: gen_tcp:recv/3.

send/2

send(Socket::inet:socket(), Packet::iodata()) -> ok | {error, atom()}

Send data on a socket.

See also: gen_tcp:send/2.

sendfile/2

sendfile(Socket::inet:socket(), Filename::file:name_all()) -> {ok, non_neg_integer()} | {error, atom()}

Equivalent to sendfile(Socket, File, Offset, Bytes, []).

sendfile/4

sendfile(Socket::inet:socket(), File::file:name_all() | file:fd(), Offset::non_neg_integer(), Bytes::non_neg_integer()) -> {ok, non_neg_integer()} | {error, atom()}

Equivalent to sendfile(Socket, File, Offset, Bytes, []).

sendfile/5

sendfile(Socket::inet:socket(), Filename::file:name_all() | file:fd(), Offset::non_neg_integer(), Bytes::non_neg_integer(), Opts::[{chunk_size, non_neg_integer()}]) -> {ok, non_neg_integer()} | {error, atom()}

Send part of a file on a socket.

As with sendfile/2 this is the optimal way to send (parts) of files using TCP. Note that unlike file:sendfile/5 this function accepts either a raw file or a file name and the ordering of arguments is different.

See also: file:sendfile/5.

setopts/2

setopts(Socket::inet:socket(), Opts::list()) -> ok | {error, atom()}

Set options on the given socket.

See also: inet:setopts/2.

sockname/1

sockname(Socket::inet:socket()) -> {ok, {inet:ip_address(), inet:port_number()}} | {error, atom()}

Return the local address and port of the connection.

See also: inet:sockname/1.


Generated by EDoc, Nov 19 2013, 11:10:19.