accept(ListenSocket)->{ok,Socket}|{error,Reason}accept(ListenSocket,Timeout::infinity)->
{ok, Socket} | {error, Reason}
Types:
ListenSocket = Socket = socket()
Reason = posix() | closed | invalid()
Accept a connection on a socket.
This call is used with connection oriented socket types (stream or seqpacket). It returns the
first pending incoming connection for a listen socket, or waits for one to arrive, and returns the
(newly) connected socket.
accept(ListenSocket,Timeout::integer()>=0)->
{ok, Socket} | {error, Reason}
Types:
ListenSocket = Socket = socket()
Reason = posix() | closed | invalid() | timeout
The same as accept/1 but returns {error,timeout} if no connection has been accepted after Timeout
milliseconds.
accept(ListenSocket,Timeout::nowait)->
{ok, Socket} | {select, SelectInfo} | {error, Reason}
accept(ListenSocket,SelectHandle::select_handle())->
{ok, Socket} | {select, SelectInfo} | {error, Reason}
Types:
ListenSocket = Socket = socket()
SelectInfo = select_info()
Reason = posix() | closed | invalid()
The same as accept/1 but returns promptly.
When there is no pending connection to return, the function will return {select,SelectInfo}, and
the caller will later receive a select message, {'$socket',Socket,select,SelectHandle} ( with
the SelectHandle contained in the SelectInfo ) when a client connects. A subsequent call to
accept/1,2 will then return the socket.
If the time-out argument is SelectHandle, that term will be contained in a returned SelectInfo and
the corresponding select message. The SelectHandle is presumed to be unique to this call.
If the time-out argument is nowait, and a SelectInfo is returned, it will contain a
select_handle() generated by the call.
If the caller doesn't want to wait for a connection, it must immediately call cancel/2 to cancel
the operation.
bind(Socket,Addr)->ok|{error,Reason}
Types:
Socket = socket()
Addr = sockaddr() | any | broadcast | loopback
Reason = posix() | closed | invalid()
Bind a name to a socket.
When a socket is created (with open), it has no address assigned to it. bind assigns the address
specified by the Addr argument.
The rules used for name binding vary between domains.
If you bind a socket to an address in for example the 'inet' or 'inet6' address families, with an
ephemeral port number (0), and want to know which port that was chosen, you can find out using
something like: {ok,#{port:=Port}}=socket:sockname(Socket)cancel(Socket,SelectInfo)->ok|{error,Reason}
Types:
Socket = socket()
SelectInfo = select_info()
Reason = closed | invalid()
Cancel an asynchronous request.
Call this function in order to cancel a previous asynchronous call to, e.g. recv/3.
An ongoing asynchronous operation blocks the socket until the operation has been finished in good
order, or until it has been cancelled by this function.
Any other process that tries an operation of the same basic type (accept / send / recv) will be
enqueued and notified with the regular select mechanism for asynchronous operations when the
current operation and all enqueued before it has been completed.
If SelectInfo does not match an operation in progress for the calling process, this function
returns {error,{invalid,SelectInfo}}.
close(Socket)->ok|{error,Reason}
Types:
Socket = socket()
Reason = posix() | closed | timeout
Closes the socket.
Note:
Note that for e.g. protocol = tcp, most implementations doing a close does not guarantee that any
data sent is delivered to the recipient before the close is detected at the remote side.
One way to handle this is to use the shutdown function (socket:shutdown(Socket,write)) to signal
that no more data is to be sent and then wait for the read side of the socket to be closed.
connect(Socket,SockAddr)->ok|{error,Reason}connect(Socket,SockAddr,Timeout::infinity)->
ok | {error, Reason}
Types:
Socket = socket()
SockAddr = sockaddr()
Reason = posix() | closed | invalid() | already
This function connects the socket to the address specified by the SockAddr argument, and returns
when the connection has been established or failed.
If a connection attempt is already in progress (by another process), {error,already} is returned.
connect(Socket,SockAddr,Timeout::integer()>=0)->
ok | {error, Reason}
Types:
Socket = socket()
SockAddr = sockaddr()
Reason = posix() | closed | invalid() | already | timeout
The same as connect/2 but returns {error,timeout} if no connection has been established after
Timeout milliseconds.
Note:
Note that when this call has returned {error,timeout the connection state of the socket is
uncertain since the platform's network stack may complete the connection at any time, up to some
platform specific time-out.
Repeating a connection attempt towards the same address would be ok, but towards a different
address could end up with a connection to either address.
The safe play would be to close the socket and start over.
Also note that all this applies to cancelling a connect call with a no-wait time-out described
below.
connect(Socket,SockAddr,Timeout::nowait)->
ok | {select, SelectInfo} | {error, Reason}
connect(Socket,SockAddr,SelectHandle::select_handle())->
ok | {select, SelectInfo} | {error, Reason}
Types:
Socket = socket()
SockAddr = sockaddr()
SelectInfo = select_info()
Reason = posix() | closed | invalid() | already
The same as connect/2 but returns promptly.
If it is not possible to immediately establish a connection, the function will return {select,SelectInfo}, and the caller will later receive a select message, {'$socket',Socket,select,SelectHandle} ( with the SelectHandle contained in the SelectInfo ) when the connection has been
completed or failed. A subsequent call to connect/1 will then finalize the connection and return
the result.
If the time-out argument is SelectHandle, that term will be contained in a returned SelectInfo and
the corresponding select message. The SelectHandle is presumed to be unique to this call.
If the time-out argument is nowait, and a SelectInfo is returned, it will contain a
select_handle() generated by the call.
If the caller doesn't want to wait for the connection to complete, it must immediately call
cancel/2 to cancel the operation.
connect(Socket)->ok|{error,Reason}
Types:
Socket = socket()
Reason = posix() | closed | invalid()
This function finalizes a connection setup on a socket, after calling connect(_,_,nowait|select_handle()) that returned {select,SelectInfo}, and receiving the select message {'$socket',Socket,select,SelectHandle}, and returns whether the connection setup was succesful or not.
Instead of calling this function, for backwards compatibility, it is allowed to call connect/2,3,
but that incurs more overhead since the connect address and time-out are processed in vain.
cancel_monitor(MRef)->boolean()
Types:
MRef = reference()
If MRef is a reference that the calling process obtained by calling monitor/1, this monitor is
turned off. If the monitoring is already turned off, nothing happens.
The returned value is one of the following:
true:
The monitor was found and removed. In this case, no 'DOWN' message corresponding to this
monitor has been delivered and will not be delivered.
false:
The monitor was not found and could not be removed. This probably because a 'DOWN' message
corresponding to this monitor has already been placed in the caller message queue.
Failure: It is an error if MRef refers to a monitor started by another process.
getopt(X1::socket(),
SocketOption :: {Level :: otp, Opt :: otp_socket_option()}) ->
{ok, Value :: term()} | {error, invalid() | closed}
Gets a socket option from the protocol level otp, which is this implementation's level above the
OS protocol layers.
See the type otp_socket_option() for a description of the options on this level.
getopt(X1::socket(),SocketOption::socket_option())->
{ok, Value :: term()} |
{error, posix() | invalid() | closed}
Gets a socket option from one of the OS's protocol levels. See the type socket_option() for which
options that this implementation knows about, how they are related to option names in the OS, and
if there are known pecularities with any of them.
What options are valid depends on what kind of socket it is (domain(), type() and protocol()).
See the socket options chapter of the users guide for more info.
Note:
Not all options are valid, nor possible to get, on all platforms. That is, even if "we" support an
option; it does not mean that the underlying OS does.
getopt(Socket,Level,Opt)->ok|{error,Reason}
Types:
Socket = socket()
Reason = inet:posix() | invalid() | closed
Backwards compatibility function.
The same as getopt(Socket,{Level,Opt})getopt_native(X1::socket(),
SocketOption ::
socket_option() |
{Level :: level() | (NativeLevel :: integer()),
NativeOpt :: integer()},
ValueType :: integer) ->
{ok, Value :: integer()} |
{error, posix() | invalid() | closed}
getopt_native(X1::socket(),
SocketOption ::
socket_option() |
{Level :: level() | (NativeLevel :: integer()),
NativeOpt :: integer()},
ValueType :: boolean) ->
{ok, Value :: boolean()} |
{error, posix() | invalid() | closed}
getopt_native(X1::socket(),
SocketOption ::
socket_option() |
{Level :: level() | (NativeLevel :: integer()),
NativeOpt :: integer()},
ValueSize :: integer() >= 0) ->
{ok, Value :: binary()} |
{error, posix() | invalid() | closed}
getopt_native(X1::socket(),
SocketOption ::
socket_option() |
{Level :: level() | (NativeLevel :: integer()),
NativeOpt :: integer()},
ValueSpec :: binary()) ->
{ok, Value :: binary()} |
{error, posix() | invalid() | closed}
Gets a socket option that may be unknown to our implementation, or that has a type not compatible
with our implementation, that is; in "native mode".
The socket option may be specified with an ordinary socket_option() tuple, with a known Level=level() and an integer NativeOpt, or with both an integer NativeLevel and NativeOpt.
How to decode the option value has to be specified either with ValueType, by specifying the
ValueSize for a binary() that will contain the fetched option value, or by specifying a binary()ValueSpec that will be copied to a buffer for the getsockopt() call to write the value in which
will be returned as a new binary().
If ValueType is integer a C type (int) will be fetched, if it is boolean a C type (int) will be
fetched and converted into a boolean() according to the C implementation.
What options are valid depends on what kind of socket it is (domain(), type() and protocol()).
The integer values for NativeLevel and NativeOpt as well as the Value encoding has to be deduced
from the header files for the running system.
i()->ok
Print all sockets in table format in the erlang shell.
i(InfoKeys)->ok
Types:
InfoKeys = info_keys()
Print all sockets in table format in the erlang shell. What information is included is defined by
InfoKeys.
i(Domain)->ok
Types:
Domain = inet | inet6 | local
Print a selection, based on domain, of the sockets in table format in the erlang shell.
i(Proto)->ok
Types:
Proto = sctp | tcp | udp
Print a selection, based on protocol, of the sockets in table format in the erlang shell.
i(Type)->ok
Types:
Type = dgram | seqpacket | stream
Print a selection, based on type, of the sockets in table format in the erlang shell.
i(Domain,InfoKeys)->ok
Types:
Domain = inet | inet6 | local
InfoKeys = info_keys()
Print a selection, based on domain, of the sockets in table format in the erlang shell. What
information is included is defined by InfoKeys.
i(Proto,InfoKeys)->ok
Types:
Proto = sctp | tcp | udp
InfoKeys = info_keys()
Print a selection, based on domain, of the sockets in table format in the erlang shell. What
information is included is defined by InfoKeys.
i(Type,InfoKeys)->ok
Types:
Type = dgram | seqpacket | stream
InfoKeys = info_keys()
Print a selection, based on type, of the sockets in table format in the erlang shell. What
information is included is defined by InfoKeys.
info()->info()
Get miscellaneous info about the socket library.
The function returns a map with each info item as a key-value binding.
Note:
In order to ensure data integrity, mutex'es are taken when needed. So, do not call this function
often.
info(Socket)->socket_info()
Types:
Socket = socket()
Get miscellaneous info about the socket.
The function returns a map with each info item as a key-value binding. It reflects the "current"
state of the socket.
Note:
In order to ensure data integrity, mutex'es are taken when needed. So, do not call this function
often.
ioctl(Socket,GetRequest)->{ok,IFConf}|{error,Reason}
Types:
Socket = socket()
GetRequest = gifconf
IFConf = [#{name := string, addr := sockaddr()}]
Reason = posix() | closed
Retrieve socket (device) parameters.
ioctl(Socket,GetRequest,NameOrIndex)->
{ok, Result} | {error, Reason}
Types:
Socket = socket()
GetRequest =
gifname | gifindex | gifaddr | gifdstaddr | gifbrdaddr |
gifnetmask | gifhwaddr | gifmtu | giftxqlen | gifflags
NameOrIndex = string() | integer()
Result = term()
Reason = posix() | closed
Retrieve socket (device) parameters. This function retreives a specific parameter, according to
GetRequest argument. The third argument is the (lookup) "key", identifying the interface (usually
the name of the interface).
gifname:
Get the name of the interface with the specified index (integer()).
Result, name of the interface, is a string().
gifindex:
Get the index of the interface with the specified name.
Result, interface index, is a integer().
gifaddr:
Get the address of the interface with the specified name. Result, address of the interface, is
a socket:sockaddr().
gifdstaddr:
Get the destination address of the point-to-point interface with the specified name.
Result, destination address of the interface, is a socket:sockaddr().
gifbrdaddr:
Get the droadcast address for the interface with the specified name.
Result, broadcast address of the interface, is a socket:sockaddr().
gifnetmask:
Get the network mask for the interface with the specified name.
Result, network mask of the interface, is a socket:sockaddr().
gifhwaddr:
Get the hardware address for the interface with the specified name.
Result, hardware address of the interface, is a socket:sockaddr(). The family field contains
the 'ARPHRD' device type (or an integer).
gifmtu:
Get the MTU (Maximum Transfer Unit) for the interface with the specified name.
Result, MTU of the interface, is an integer().
giftxqlen:
Get the transmit queue length of the interface with the specified name.
Result, transmit queue length of the interface, is an integer().
gifflags:
Get the active flag word of the interface with the specified name.
Result, the active flag word of the interface, is an list of socket:ioctl_device_flag()|integer().
ioctl(Socket,SetRequest,Name,Value)->ok|{error,Reason}
Types:
Socket = socket()
SetRequest =
sifflags | sifaddr | sifdstaddr | sifbrdaddr | sifnetmask |
sifhwaddr | gifmtu | siftxqlen
Name = string()
Value = term()
Reason = posix() | closed
Set socket (device) parameters. This function sets a specific parameter, according to SetRequest
argument. The third argument is the "key", identifying the interface (usually the name of the
interface), and the fourth is the "new" value.
These are privileged operation's.
sifflags:
Set the the active flag word, #{Flag=>boolean()}, of the interface with the specified name.
Each flag to be changed, should be added to the value map, with the value 'true' if the flag
(Flag) should be set and 'false' if the flag should be reset.
sifaddr:
Set the address, sockaddr(), of the interface with the specified name.
sifdstaddr:
Set the destination address, sockaddr(), of a point-to-point interface with the specified
name.
sifbrdaddr:
Set the broadcast address, sockaddr(), of the interface with the specified name.
sifnetmask:
Set the network mask, sockaddr(), of the interface with the specified name.
sifmtu:
Set the MTU (Maximum Transfer Unit), integer(), for the interface with the specified name.
siftxqlen:
Set the transmit queue length, integer(), of the interface with the specified name.
is_supported(Key1::term())->boolean()is_supported(Key1::term(),Key2::term())->boolean()
This function retreives information about what the platform supports, such as if SCTP is
supported, or if a socket options are supported.
For keys other than the known false is returned. Note that in a future version or on a different
platform there might be more supported items.
This functions returns a boolean corresponding to what supports/0-2 reports for the same Key1 (and
Key2).
listen(Socket)->ok|{error,Reason}listen(Socket,Backlog)->ok|{error,Reason}
Types:
Socket = socket()
Backlog = integer()
Reason = posix() | closed
Listen for connections on a socket.
monitor(Socket)->reference()
Types:
Socket = socket()
Start monitor the socket Socket.
If the monitored socket does not exist or when the monitor is triggered, a 'DOWN' message is sent
that has the following pattern:
{'DOWN', MonitorRef, socket, Object, Info}
In the monitor message MonitorRef and Type are the same as described earlier, and:
Object:
The monitored entity, socket, which triggered the event.
Info:
Either the termination reason of the socket or nosock (socket Socket did not exist at the time
of monitor creation).
Making several calls to socket:monitor/1 for the same Socket is not an error; it results in as
many independent monitoring instances.
number_of()->integer()>=0
Returns the number of active sockets.
open(FD)->{ok,Socket}|{error,Reason}open(FD,Opts)->{ok,Socket}|{error,Reason}
Types:
FD = integer()
Opts =
#{domain => domain() | integer(),
type => type() | integer(),
protocol => default | protocol() | integer(),
dup => boolean(),
debug => boolean(),
use_registry => boolean()}
Socket = socket()
Reason = posix() | domain | type | protocol
Creates an endpoint (socket) for communication based on an already existing file descriptor. The
function attempts to retrieve domain, type and protocol from the system. This is however not
possible on all platforms, and they should then be specified in Opts.
The Opts argument is intended for providing extra information for the open call:
domain:
Which protocol domain is the descriptor of. See also open/2,3,4.
type:
Which protocol type type is the descriptor of.
See also open/2,3,4.
protocol:
Which protocol is the descriptor of. The atom default is equivalent to the integer protocol
number 0 which means the default protocol for a given domain and type.
If the protocol can not be retrieved from the platform for the socket, and protocol is not
specified, the default protocol is used, which may or may not be correct.
See also open/2,3,4.
dup:
Shall the provided descriptor be duplicated (dup) or not.
Defaults to true.
debug:
Enable or disable debug during the open call.
Defaults to false.
use_registry>:
Enable or disable use of the socket registry for this socket. This overrides the global value.
Defaults to the global value, see use_registry/1.
Note:
This function should be used with care!
On some platforms it is necessary to provide domain, type and protocol since they cannot be
retreived from the platform.
open(Domain,Type)->{ok,Socket}|{error,Reason}open(Domain,Type,Opts)->{ok,Socket}|{error,Reason}
Types:
Domain = domain() | integer()
Type = type() | integer()
Opts = map()
Socket = socket()
Reason = posix() | protocol
Creates an endpoint (socket) for communication.
The same as open(Domain,Type,default) and open(Domain,Type,default,Opts) respectively.
open(Domain,Type,Protocol)->{ok,Socket}|{error,Reason}open(Domain,Type,Protocol,Opts)->
{ok, Socket} | {error, Reason}
Types:
Domain = domain() | integer()
Type = type() | integer()
Protocol = default | protocol() | integer()
Opts =
#{netns => string(),
debug => boolean(),
use_registry => boolean()}
Socket = socket()
Reason = posix() | protocol
Creates an endpoint (socket) for communication.
Domain and Type may be integer()s, as defined in the platform's header files. The same goes for
Protocol as defined in the platform's services(5) database. See also the OS man page for the
library call socket(2).
Note:
For some combinations of Domain and Type the platform has got a default protocol that can be
selected with Protocol=default, and the platform may allow or require selecting the default
protocol, a specific protocol, or either.
Examples:
socket:open(inet,stream,tcp):
It is common that for protocol domain and type inet,stream it is allowed to select the tcp
protocol although that mostly is the default.
socket:open(local,dgram):
It is common that for the protocol domain local it is mandatory to not select a protocol, that
is; to select the default protocol.
The Opts argument is intended for "other" options. The supported option(s) are described below:
netns:string():
Used to set the network namespace during the open call. Only supported on the Linux platform.
debug:boolean():
Enable or disable debug during the open call.
Defaults to false.
use_registry:boolean():
Enable or disable use of the socket registry for this socket. This overrides the global value.
Defaults to the global value, see use_registry/1.
peername(Socket)->{ok,SockAddr}|{error,Reason}
Types:
Socket = socket()
SockAddr = sockaddr_recv()
Reason = posix() | closed
Returns the address of the peer connected to the socket.
recv(Socket)->
{ok, Data} | {error, Reason} | {error, {Reason, Data}}
recv(Socket,Flags)->
{ok, Data} | {error, Reason} | {error, {Reason, Data}}
recv(Socket,Length)->
{ok, Data} | {error, Reason} | {error, {Reason, Data}}
recv(Socket,Flags,Timeout::infinity)->
{ok, Data} | {error, Reason} | {error, {Reason, Data}}
recv(Socket,Length,Flags)->
{ok, Data} | {error, Reason} | {error, {Reason, Data}}
recv(Socket,Length,Timeout::infinity)->
{ok, Data} | {error, Reason} | {error, {Reason, Data}}
recv(Socket,Length,Flags,Timeout::infinity)->
{ok, Data} | {error, Reason} | {error, {Reason, Data}}
Types:
Socket = socket()
Length = integer() >= 0
Flags = [msg_flag() | integer()]
Data = binary()
Reason = posix() | closed | invalid()
Receives data from a socket, waiting for it to arrive.
The argument Length specifies how many bytes to receive, with the special case 0 meaning "all
available".
For a socket of type stream this call will not return until all requested data can be delivered,
or if "all available" data was requested when the first data chunk arrives.
The message Flags may be symbolic msg_flag()s and/or integer()s, as in the platform's appropriate
header files. The values of all symbolic flags and integers are or:ed together.
When there is a socket error this function returns {error,Reason}, or if some data arrived before
the error; {error,{Reason,Data}}.
recv(Socket,Flags,Timeout::integer()>=0)->
{ok, Data} | {error, Reason} | {error, {Reason, Data}}
recv(Socket,Length,Timeout::integer()>=0)->
{ok, Data} | {error, Reason} | {error, {Reason, Data}}
recv(Socket,Length,Flags,Timeout::integer()>=0)->
{ok, Data} | {error, Reason} | {error, {Reason, Data}}
Types:
Socket = socket()
Length = integer() >= 0
Flags = [msg_flag() | integer()]
Data = binary()
Reason = posix() | closed | invalid() | timeout
Receives data from a socket, waiting at most Timeout milliseconds for it to arrive.
The same as infinite time-out recv/1,2,3,4 but returns {error,timeout} or {error,{timeout,Data}} after Timeout milliseconds, if the requested data has not been delivered.
recv(Socket,Flags,SelectHandle::nowait)->
{ok, Data} |
{select, SelectInfo} |
{select, {SelectInfo, Data}} |
{error, Reason} |
{error, {Reason, Data}}
recv(Socket,Flags,SelectHandle::select_handle())->
{ok, Data} |
{select, SelectInfo} |
{select, {SelectInfo, Data}} |
{error, Reason} |
{error, {Reason, Data}}
recv(Socket,Length,SelectHandle::nowait)->
{ok, Data} |
{select, SelectInfo} |
{select, {SelectInfo, Data}} |
{error, Reason} |
{error, {Reason, Data}}
recv(Socket,Length,SelectHandle::select_handle())->
{ok, Data} |
{select, SelectInfo} |
{select, {SelectInfo, Data}} |
{error, Reason} |
{error, {Reason, Data}}
recv(Socket,Length,Flags,SelectHandle::nowait)->
{ok, Data} |
{select, SelectInfo} |
{select, {SelectInfo, Data}} |
{error, Reason} |
{error, {Reason, Data}}
recv(Socket,Length,Flags,SelectHandle::select_handle())->
{ok, Data} |
{select, SelectInfo} |
{select, {SelectInfo, Data}} |
{error, Reason} |
{error, {Reason, Data}}
Types:
Socket = socket()
Length = integer() >= 0
Flags = [msg_flag() | integer()]
Data = binary()
SelectInfo = select_info()
Reason = posix() | closed | invalid()
Receives data from a socket, but returns a select continuation if the data could not be returned
immediately.
The same as infinite time-out recv/1,2,3,4 but if the data cannot be delivered immediately, the
function returns {select,SelectInfo}, and the caller will then receive a select message,
{'$socket',Socket,select,SelectHandle} ( with the SelectHandle contained in the SelectInfo )
when data has arrived. A subsequent call to recv/1,2,3,4 will then return the data.
If the time-out argument is SelectHandle, that term will be contained in a returned SelectInfo and
the corresponding select message. The SelectHandle is presumed to be unique to this call.
If the time-out argument is nowait, and a SelectInfo is returned, it will contain a
select_handle() generated by the call.
Note that for a socket of type stream, if Length>0 and only part of that amount of data is
available, the function will return {ok,{Data,SelectInfo with partial data. If the caller
doesn't want to wait for more data, it must immediately call cancel/2 to cancel the operation.
recvfrom(Socket)->{ok,{Source,Data}}|{error,Reason}recvfrom(Socket,Flags)->{ok,{Source,Data}}|{error,Reason}recvfrom(Socket,BufSz)->{ok,{Source,Data}}|{error,Reason}recvfrom(Socket,Flags,Timeout::infinity)->
{ok, {Source, Data}} | {error, Reason}
recvfrom(Socket,BufSz,Flags)->
{ok, {Source, Data}} | {error, Reason}
recvfrom(Socket,BufSz,Timeout::infinity)->
{ok, {Source, Data}} | {error, Reason}
recvfrom(Socket,BufSz,Flags,Timeout::infinity)->
{ok, {Source, Data}} | {error, Reason}
Types:
Socket = socket()
BufSz = integer() >= 0
Flags = [msg_flag() | integer()]
Source = sockaddr_recv()
Data = binary()
Reason = posix() | closed | invalid()
Receive a message from a socket, waiting for it to arrive.
The function returns when a message is received, or when there is a socket error. Argument BufSz
specifies the number of bytes for the receive buffer. If the buffer size is too small, the message
will be truncated.
If BufSz is not specified or 0, a default buffer size is used, which can be set by
socket:setopt(Socket,{otp,recvbuf},BufSz).
If it is impossible to know the appropriate buffer size, it may be possible to use the receive
message flag peek. When this flag is used, the message is not "consumed" from the underlying
buffers, so another recvfrom/1,2,3,4 call is needed, possibly with an adjusted buffer size.
The message Flags may be symbolic msg_flag()s and/or integer()s, as in the platform's appropriate
header files. The values of all symbolic flags and integers are or:ed together.
recvfrom(Socket,Flags,Timeout::integer()>=0)->
{ok, {Source, Data}} | {error, Reason}
recvfrom(Socket,BufSz,Timeout::integer()>=0)->
{ok, {Source, Data}} | {error, Reason}
recvfrom(Socket,BufSz,Flags,Timeout::integer()>=0)->
{ok, {Source, Data}} | {error, Reason}
Types:
Socket = socket()
BufSz = integer() >= 0
Flags = [msg_flag() | integer()]
Source = sockaddr_recv()
Data = binary()
Reason = posix() | closed | invalid() | timeout
Receives a message from a socket, waiting at most Timeout milliseconds for it to arrive.
The same as infinite time-out recvfrom/1,2,3,4 but returns {error,timeout} after Timeout
milliseconds, if no message has been delivered.
recvfrom(Socket,Flags,SelectHandle::nowait)->
{ok, {Source, Data}} |
{select, SelectInfo} |
{error, Reason}
recvfrom(Socket,Flags,SelectHandle::select_handle())->
{ok, {Source, Data}} |
{select, SelectInfo} |
{error, Reason}
recvfrom(Socket,BufSz,SelectHandle::nowait)->
{ok, {Source, Data}} |
{select, SelectInfo} |
{error, Reason}
recvfrom(Socket,BufSz,SelectHandle::select_handle())->
{ok, {Source, Data}} |
{select, SelectInfo} |
{error, Reason}
recvfrom(Socket,BufSz,Flags,SelectHandle::nowait)->
{ok, {Source, Data}} |
{select, SelectInfo} |
{error, Reason}
recvfrom(Socket,BufSz,Flags,SelectHandle::select_handle())->
{ok, {Source, Data}} |
{select, SelectInfo} |
{error, Reason}
Types:
Socket = socket()
BufSz = integer() >= 0
Flags = [msg_flag() | integer()]
Source = sockaddr_recv()
Data = binary()
SelectInfo = select_info()
Reason = posix() | closed | invalid()
Receives a message from a socket, but returns a select continuation if no message could be
returned immediately.
The same as infinite time-out recvfrom/1,2,3,4 but if no message cannot delivered immediately,
the function returns {select,SelectInfo}, and the caller will then receive a select message,
{'$socket',Socket,select,SelectHandle} ( with the SelectHandle contained in the SelectInfo )
when data has arrived. A subsequent call to recvfrom/1,2,3,4 will then return the message.
If the time-out argument is SelectHandle, that term will be contained in a returned SelectInfo and
the corresponding select message. The SelectHandle is presumed to be unique to this call.
If the time-out argument is nowait, and a SelectInfo is returned, it will contain a
select_handle() generated by the call.
If the caller doesn't want to wait for the data, it must immediately call cancel/2 to cancel the
operation.
recvmsg(Socket)->{ok,Msg}|{error,Reason}recvmsg(Socket,Flags)->{ok,Msg}|{error,Reason}recvmsg(Socket,Timeout::infinity)->
{ok, Msg} | {error, Reason}
recvmsg(Socket,Flags,Timeout::infinity)->
{ok, Msg} | {error, Reason}
recvmsg(Socket,BufSz,CtrlSz)->{ok,Msg}|{error,Reason}recvmsg(Socket,BufSz,CtrlSz,Timeout::infinity)->
{ok, Msg} | {error, Reason}
recvmsg(Socket,BufSz,CtrlSz,Flags,Timeout::infinity)->
{ok, Msg} | {error, Reason}
Types:
Socket = socket()
BufSz = CtrlSz = integer() >= 0
Flags = [msg_flag() | integer()]
Msg = msg_recv()
Reason = posix() | closed | invalid()
Receive a message from a socket, waiting for it to arrive.
The function returns when a message is received, or when there is a socket error. Arguments BufSz
and CtrlSz specifies the number of bytes for the receive buffer and the control message buffer. If
the buffer size(s) is(are) too small, the message and/or control message list will be truncated.
If BufSz is not specified or 0, a default buffer size is used, which can be set by
socket:setopt(Socket,{otp,recvbuf},BufSz). The same applies to CtrlSz and socket:setopt(Socket,{otp,recvctrlbuf},CtrlSz).
If it is impossible to know the appropriate buffer size, it may be possible to use the receive
message flag peek. When this flag is used, the message is not "consumed" from the underlying
buffers, so another recvfrom/1,2,3,4,5 call is needed, possibly with an adjusted buffer size.
The message Flags may be symbolic msg_flag()s and/or integer()s, as in the platform's appropriate
header files. The values of all symbolic flags and integers are or:ed together.
recvmsg(Socket,Timeout::integer()>=0)->
{ok, Msg} | {error, Reason}
recvmsg(Socket,Flags,Timeout::integer()>=0)->
{ok, Msg} | {error, Reason}
recvmsg(Socket,BufSz,CtrlSz,Timeout::integer()>=0)->
{ok, Msg} | {error, Reason}
recvmsg(Socket,BufSz,CtrlSz,Flags,
Timeout :: integer() >= 0) ->
{ok, Msg} | {error, Reason}
Types:
Socket = socket()
BufSz = CtrlSz = integer() >= 0
Flags = [msg_flag() | integer()]
Msg = msg_recv()
Reason = posix() | closed | invalid() | timeout
Receives a message from a socket, waiting at most Timeout milliseconds for it to arrive.
The same as recvmsg/1,2,3,4,5 but returns {error,timeout} after Timeout milliseconds, if no
message has been delivered.
recvmsg(Socket,Timeout::nowait)->
{ok, Msg} | {select, SelectInfo} | {error, Reason}
recvmsg(Socket,SelectHandle::select_handle())->
{ok, Msg} | {select, SelectInfo} | {error, Reason}
recvmsg(Socket,Flags,Timeout::nowait)->
{ok, Msg} | {select, SelectInfo} | {error, Reason}
recvmsg(Socket,Flags,SelectHandle::select_handle())->
{ok, Msg} | {select, SelectInfo} | {error, Reason}
recvmsg(Socket,BufSz,CtrlSz,SelectHandle::nowait)->
{ok, Msg} | {select, SelectInfo} | {error, Reason}
recvmsg(Socket,BufSz,CtrlSz,SelectHandle::select_handle())->
{ok, Msg} | {select, SelectInfo} | {error, Reason}
recvmsg(Socket,BufSz,CtrlSz,Flags,SelectHandle::nowait)->
{ok, Msg} | {select, SelectInfo} | {error, Reason}
recvmsg(Socket,BufSz,CtrlSz,Flags,
SelectHandle :: select_handle()) ->
{ok, Msg} | {select, SelectInfo} | {error, Reason}
Types:
Socket = socket()
BufSz = CtrlSz = integer() >= 0
Flags = [msg_flag() | integer()]
Msg = msg_recv()
SelectInfo = select_info()
Reason = posix() | closed | invalid()
Receives a message from a socket, but returns a select continuation if no message could be
returned immediately.
The same as infinite time-out recvfrom/1,2,3,4 but if no message cannot delivered immediately,
the function returns {select,SelectInfo}, and the caller will then receive a select message,
{'$socket',Socket,select,SelectHandle} ( with the SelectHandle contained in the SelectInfo )
when data has arrived. A subsequent call to recvmsg/1,2,3,4,5 will then return the data.
If the time-out argument is SelectHandle, that term will be contained in a returned SelectInfo and
the corresponding select message. The SelectHandle is presumed to be unique to this call.
If the time-out argument is nowait, and a SelectInfo is returned, it will contain a
select_handle() generated by the call.
If the caller doesn't want to wait for the data, it must immediately call cancel/2 to cancel the
operation.
send(Socket,Data)->
ok |
{ok, RestData} |
{error, Reason} |
{error, {Reason, RestData}}
send(Socket,Data,Flags)->
ok |
{ok, RestData} |
{error, Reason} |
{error, {Reason, RestData}}
send(Socket,Data,Timeout::infinity)->
ok |
{ok, RestData} |
{error, Reason} |
{error, {Reason, RestData}}
send(Socket,Data,Flags,Timeout::infinity)->
ok |
{ok, RestData} |
{error, Reason} |
{error, {Reason, RestData}}
Types:
Socket = socket()
Data = iodata()
Flags = [msg_flag() | integer()]
RestData = binary()
Reason = posix() | closed | invalid()
Sends data on a connected socket, waiting for it to be sent.
This call will not return until the Data has been accepted by the platform's network layer, or it
reports an error.
The message Flags may be symbolic msg_flag()s and/or integer()s, matching the platform's
appropriate header files. The values of all symbolic flags and integers are or:ed together.
The Data, if it is not a binary(), is copied into one before calling the platform network API,
because a single buffer is required. A returned RestData is a sub binary of this data binary.
The return value indicates the result from the platform's network layer:
ok:
All data has been accepted.
{ok,RestData}:
Not all data has been accepted, but no error has been reported. RestData is the tail of Data
that has not been accepted.
This cannot happen for a socket of type stream where a partially succesful send is retried
until the data is either accepted or there is an error.
For a socket of type dgram this should probably also not happen since a message that cannot be
passed atomically should render an error.
It is nevertheless possible for the platform's network layer to return this.
{error,Reason}:
An error has been reported and no data has been accepted. The posix()Reasons are from the
platform's network layer. closed means that this socket library knows that the socket is
closed, and invalid() means that something about an argument is invalid.
{error, {Reason, RestData}} : An error has been reported but before that some data was
accepted. RestData is the tail of Data that has not been accepted. See {error,Reason} above.
This can only happen for a socket of type stream when a partially succesful send is retried
untill there is an error.
send(Socket,Data,Timeout::integer()>=0)->
ok |
{ok, RestData} |
{error, Reason | timeout} |
{error, {Reason | timeout, RestData}}
send(Socket,Data,Flags,Timeout::integer()>=0)->
ok |
{ok, RestData} |
{error, Reason | timeout} |
{error, {Reason | timeout, RestData}}
Types:
Socket = socket()
Data = iodata()
Flags = [msg_flag() | integer()]
RestData = binary()
Reason = posix() | closed | invalid()
Sends data on a connected socket, waiting at most Timeout milliseconds for it to be sent.
The same as infinite time-out send/2,3,4 but returns {error,timeout} or {error,{timeout,RestData}} after Timeout milliseconds, if no Data or only some of it was accepted by the
platform's network layer.
send(Socket,Data,SelectHandle::nowait)->
ok |
{ok, RestData} |
{select, SelectInfo} |
{select, {SelectInfo, RestData}} |
{error, Reason}
send(Socket,Data,SelectHandle::select_handle())->
ok |
{ok, RestData} |
{select, SelectInfo} |
{select, {SelectInfo, RestData}} |
{error, Reason}
send(Socket,Data,Flags,SelectHandle::nowait)->
ok |
{ok, RestData} |
{select, SelectInfo} |
{select, {SelectInfo, RestData}} |
{error, Reason}
send(Socket,Data,Flags,SelectHandle::select_handle())->
ok |
{ok, RestData} |
{select, SelectInfo} |
{select, {SelectInfo, RestData}} |
{error, Reason}
Types:
Socket = socket()
Data = iodata()
Flags = [msg_flag() | integer()]
RestData = binary()
SelectInfo = select_info()
Reason = posix() | closed | invalid()
Sends data on a connected socket, but returns a select continuation if the data could not be sent
immediately.
The same as infinite time-out send/2,3 but if the data is not immediately accepted by the
platform network layer, the function returns {select,SelectInfo}, and the caller will then
receive a select message, {'$socket',Socket,select,SelectHandle} ( with the SelectHandle that
was contained in the SelectInfo ) when there is room for more data. A subsequent call to send/2-4
will then send the data.
If SelectHandle is a select_handle(), that term will be contained in a returned SelectInfo and the
corresponding select message. The SelectHandle is presumed to be unique to this call.
If SelectHandle is nowait, and a SelectInfo is returned, it will contain a select_handle()
generated by the call.
If some of the data was sent, the function will return {ok,{RestData,SelectInfo}, which can
only happen for a socket of type stream. If the caller does not want to wait to send the rest of
the data, it should immediately cancel the operation with cancel/2.
send(Socket,Data,Cont)->
ok |
{ok, RestData} |
{error, Reason} |
{error, {Reason, RestData}}
send(Socket,Data,Cont,Timeout::infinity)->
ok |
{ok, RestData} |
{error, Reason} |
{error, {Reason, RestData}}
send(Socket,Data,Cont,Timeout::integer()>=0)->
ok |
{ok, RestData} |
{error, Reason | timeout} |
{error, {Reason | timeout, RestData}}
send(Socket,Data,Cont,SelectHandle::nowait)->
ok |
{ok, RestData} |
{select, SelectInfo} |
{select, {SelectInfo, RestData}} |
{error, Reason}
send(Socket,Data,Cont,SelectHandle::select_handle())->
ok |
{ok, RestData} |
{select, SelectInfo} |
{select, {SelectInfo, RestData}} |
{error, Reason}
Types:
Socket = socket()
Data = iodata()
Cont = select_info()
RestData = binary()
SelectInfo = select_info()
Reason = posix() | closed | invalid()
Continues sending data on a connected socket, where the send operation was initiated by send/3,4
that returned a SelectInfo continuation. Otherwise like infinite time-out send/2,3,4 , limited
time-out send/3,4 or nowait send/3,4 respectively.
Cont is the SelectInfo that was returned from the previous send() call.
If Data is not a binary(), it will be copied into one, again.
The return value indicates the result from the platform's network layer. See send/2,3,4 and nowait
send/3,4.
sendmsg(Socket,Msg)->
ok |
{ok, RestData} |
{error, Reason} |
{error, {Reason, RestData}}
sendmsg(Socket,Msg,Flags)->
ok |
{ok, RestData} |
{error, Reason} |
{error, {Reason, RestData}}
sendmsg(Socket,Msg,Timeout::infinity)->
ok |
{ok, RestData} |
{error, Reason} |
{error, {Reason, RestData}}
sendmsg(Socket,Msg,Flags,Timeout::infinity)->
ok |
{ok, RestData} |
{error, Reason} |
{error, {Reason, RestData}}
Types:
Socket = socket()
Msg = msg_send()
Flags = [msg_flag() | integer()]
RestData = erlang:iovec()
Reason = posix() | closed | invalid()
Sends a message on a socket, waiting for it to be sent.
The destination, if needed, that is: if the socket is not connected, is provided in Msg, which
also contains the data to send as a list of binaries. Msg may also contain an list of optional
control messages (depending on what the protocol and platform supports).
For a connected socket no address field should be present in Msg, the platform may return an error
or ignore one.
The message data is given to to the platform's network layer in the form of an I/O vector without
copying the content. If the number of elements in the I/O vector is larger than allowed on the
platform (reported in the iov_max field from info/0), on a socket of type stream the send is
iterated over all elements, but for other socket types the call fails.
This call will not return until the data has been handed over to the platform's network layer, or
when it reports an error.
The message Flags may be symbolic msg_flag()s and/or integer()s, matching the platform's
appropriate header files. The values of all symbolic flags and integers are or:ed together.
The return value indicates the result from the platform's network layer. See send/2,3,4.
sendmsg(Socket,Msg,Timeout::integer()>=0)->
ok |
{ok, RestData} |
{error, Reason | timeout} |
{error, {Reason | timeout, RestData}}
sendmsg(Socket,Msg,Flags,Timeout::integer()>=0)->
ok |
{ok, RestData} |
{error, Reason | timeout} |
{error, {Reason | timeout, RestData}}
Types:
Socket = socket()
Msg = msg_send()
Flags = [msg_flag() | integer()]
RestData = erlang:iovec()
Reason = posix() | closed | invalid()
Sends a message on a socket, waiting at most Timeout milliseconds for it to be sent.
The same as infinite time-out sendmsg/2,3,4 but returns {error,timeout} or {error,{timeout,RestData}} after Timeout milliseconds, if no data or only some of it was accepted by the
platform's network layer.
sendmsg(Socket,Msg,Timeout::nowait)->
ok |
{ok, RestData} |
{select, SelectInfo} |
{select, {SelectInfo, RestData}} |
{error, Reason} |
{error, {Reason, RestData}}
sendmsg(Socket,Msg,SelectHandle::select_handle())->
ok |
{ok, RestData} |
{select, SelectInfo} |
{select, {SelectInfo, RestData}} |
{error, Reason} |
{error, {Reason, RestData}}
sendmsg(Socket,Msg,Flags,SelectHandle::nowait)->
ok |
{ok, RestData} |
{select, SelectInfo} |
{select, {SelectInfo, RestData}} |
{error, Reason} |
{error, {Reason, RestData}}
sendmsg(Socket,Msg,Flags,SelectHandle::select_handle())->
ok |
{ok, RestData} |
{select, SelectInfo} |
{select, {SelectInfo, RestData}} |
{error, Reason} |
{error, {Reason, RestData}}
Types:
Socket = socket()
Msg = msg_send()
Flags = [msg_flag() | integer()]
RestData = erlang:iovec()
SelectInfo = select_info()
Reason = posix() | closed | invalid()
Sends a message on a socket, but returns a select continuation if the data could not be sent
immediately.
The same as infinity time-out sendmsg/2,3 but if the data is not immediately accepted by the
platform network layer, the function returns {select,SelectInfo}, and the caller will then
receive a select message, {'$socket',Socket,select,SelectHandle} ( with the SelectHandle that
was contained in the SelectInfo ) when there is room for more data. A subsequent call to
sendmsg/2-4 will then send the data.
If SelectHandle, is a select_handle(), that term will be contained in a returned SelectInfo and
the corresponding select message. The SelectHandle is presumed to be unique to this call.
If SelectHandle is nowait, and a SelectInfo is returned, it will contain a select_handle()
generated by the call.
If some of the data was sent, the function will return {ok,{RestData,SelectInfo}, which can
only happen for a socket of type stream. If the caller does not want to wait to send the rest of
the data, it should immediately cancel the operation with cancel/2.
sendmsg(Socket,Data,Cont)->
ok |
{ok, RestData} |
{error, Reason} |
{error, {Reason, RestData}}
sendmsg(Socket,Data,Cont,Timeout::infinity)->
ok |
{ok, RestData} |
{error, Reason} |
{error, {Reason, RestData}}
sendmsg(Socket,Data,Cont,Timeout::integer()>=0)->
ok |
{ok, RestData} |
{error, Reason | timeout} |
{error, {Reason | timeout, RestData}}
sendmsg(Socket,Data,Cont,SelectHandle::nowait)->
ok |
{ok, RestData} |
{select, SelectInfo} |
{select, {SelectInfo, RestData}} |
{error, Reason} |
{error, {Reason, RestData}}
sendmsg(Socket,Data,Cont,SelectHandle::select_handle())->
ok |
{ok, RestData} |
{select, SelectInfo} |
{select, {SelectInfo, RestData}} |
{error, Reason} |
{error, {Reason, RestData}}
Types:
Socket = socket()
Data = msg_send() | erlang:iovec()
Cont = select_info()
RestData = erlang:iovec()
SelectInfo = select_info()
Reason = posix() | closed | invalid()
Continues sending a message data on a socket, where the send operation was initiated by
sendmsg/3,4 that returned a SelectInfo continuation. Otherwise like infinite time-out
sendmsg/2,3,4 , limited time-out sendmsg/3,4 or nowait sendmsg/3,4 respectively.
Cont is the SelectInfo that was returned from the previous sendmsg() call.
The return value indicates the result from the platform's network layer. See send/2,3,4 and nowait
sendmsg/3,4.
sendto(Socket,Data,Dest)->
ok |
{ok, RestData} |
{error, Reason} |
{error, {Reason, RestData}}
sendto(Socket,Data,Dest,Flags)->
ok |
{ok, RestData} |
{error, Reason} |
{error, {Reason, RestData}}
sendto(Socket,Data,Dest,Timeout::infinity)->
ok |
{ok, RestData} |
{error, Reason} |
{error, {Reason, RestData}}
sendto(Socket,Data,Dest,Flags,Timeout::infinity)->
ok |
{ok, RestData} |
{error, Reason} |
{error, {Reason, RestData}}
Types:
Socket = socket()
Data = iodata()
Dest = sockaddr()
Flags = [msg_flag() | integer()]
RestData = binary()
Reason = posix() | closed | invalid()
Sends data on a socket, to the specified destination, waiting for it to be sent.
This call will not return until the data has been accepted by the platform's network layer, or it
reports an error.
If this call is used on a connection mode socket or on a connected socket, the platforms's network
layer may return an error or ignore the destination address.
The message Flags may be symbolic msg_flag()s and/or integer()s, matching the platform's
appropriate header files. The values of all symbolic flags and integers are or:ed together.
The return value indicates the result from the platform's network layer. See send/2,3,4.
sendto(Socket,Data,Dest,Timeout::integer()>=0)->
ok |
{ok, RestData} |
{error, Reason | timeout} |
{error, {Reason | timeout, RestData}}
sendto(Socket,Data,Dest,Flags,Timeout::integer()>=0)->
ok |
{ok, RestData} |
{error, Reason | timeout} |
{error, {Reason | timeout, RestData}}
Types:
Socket = socket()
Data = iodata()
Dest = sockaddr()
Flags = [msg_flag() | integer()]
RestData = binary()
Reason = posix() | closed | invalid()
Sends data on a socket, waiting at most Timeout milliseconds for it to be sent.
The same as infinite time-out sendto/3,4,5 but returns {error,timeout} or {error,{timeout,RestData}} after Timeout milliseconds, if no Data or only some of it was accepted by the
platform's network layer.
sendto(Socket,Data,Dest,SelectHandle::nowait)->
ok |
{ok, RestData} |
{select, SelectInfo} |
{select, {SelectInfo, RestData}} |
{error, Reason}
sendto(Socket,Data,Dest,SelectHandle::select_handle())->
ok |
{ok, RestData} |
{select, SelectInfo} |
{select, {SelectInfo, RestData}} |
{error, Reason}
sendto(Socket,Data,Dest,Flags,SelectHandle::nowait)->
ok |
{ok, RestData} |
{select, SelectInfo} |
{select, {SelectInfo, RestData}} |
{error, Reason}
sendto(Socket,Data,Dest,Flags,SelectHandle::select_handle())->
ok |
{ok, RestData} |
{select, SelectInfo} |
{select, {SelectInfo, RestData}} |
{error, Reason}
Types:
Socket = socket()
Data = iodata()
Dest = sockaddr()
Flags = [msg_flag() | integer()]
RestData = binary()
SelectInfo = select_info()
Reason = posix() | closed | invalid()
Sends data on a socket, but returns a select continuation if the data could not be sent
immediately.
The same as infinity time-out sendto/3,4 but if the data is not immediately accepted by the
platform network layer, the function returns {select,SelectInfo}, and the caller will then
receive a select message, {'$socket',Socket,select,SelectHandle} ( with the SelectHandle that
was contained in the SelectInfo ) when there is room for more data. A subsequent call to
sendto/3-5 will then send the data.
If SelectHandle is a select_handle(), that term will be contained in a returned SelectInfo and the
corresponding select message. The SelectHandle is presumed to be unique to this call.
If SelectHandle is nowait, and a SelectInfo is returned, it will contain a select_handle()
generated by the call.
If some of the data was sent, the function will return {ok,{RestData,SelectInfo}, which can
only happen for a socket of type stream. If the caller does not want to wait to send the rest of
the data, it should immediately cancel the operation with cancel/2.
sendto(Socket,Data,Cont)->
ok |
{ok, RestData} |
{error, Reason} |
{error, {Reason, RestData}}
sendto(Socket,Data,Cont,Timeout::infinity)->
ok |
{ok, RestData} |
{error, Reason} |
{error, {Reason, RestData}}
sendto(Socket,Data,Cont,Timeout::integer()>=0)->
ok |
{ok, RestData} |
{error, Reason | timeout} |
{error, {Reason | timeout, RestData}}
sendto(Socket,Data,Cont,SelectHandle::nowait)->
ok |
{ok, RestData} |
{select, SelectInfo} |
{select, {SelectInfo, RestData}} |
{error, Reason}
sendto(Socket,Data,Cont,SelectHandle::select_handle())->
ok |
{ok, RestData} |
{select, SelectInfo} |
{select, {SelectInfo, RestData}} |
{error, Reason}
Types:
Socket = socket()
Data = iodata()
Cont = select_info()
RestData = binary()
SelectInfo = select_info()
Reason = posix() | closed | invalid()
Continues sending data on a socket, where the send operation was initiated by sendto/4,5 that
returned a SelectInfo continuation. Otherwise like infinite time-out sendto/3,4,5 , limited
time-out sendto/4,5 or nowait sendto/4,5 respectively.
Cont is the SelectInfo that was returned from the previous sendto() call.
If Data is not a binary(), it will be copied into one, again.
The return value indicates the result from the platform's network layer. See send/2,3,4 and nowait
sendto/4,5.
sendfile(Socket,FileHandle,Offset,Count,Timeout::infinity)->
{ok, BytesSent} |
{error, Reason} |
{error, {Reason, BytesSent}}
Types:
Socket = socket()
FileHandle = file:fd()
Offset = integer()
Count = BytesSent = integer() >= 0
Reason = posix() | closed | invalid()
Sends file data on a socket, to the specified destination, waiting for it to be sent ("infinite"time-out).
The FileHandle must refer to an open raw file as described in file:open/2.
This call will not return until the data has been accepted by the platform's network layer, or it
reports an error.
The Offset argument is the file offset to start reading from. The default value is 0.
The Count argument is the number of bytes to transfer from FileHandle to Socket. If Count=:=0
(the default) the transfer stops at the end of file.
The return value indicates the result from the platform's network layer:
{ok,BytesSent}:
The transfer completed succesfully after BytesSent bytes of data.
{error,Reason}:
An error has been reported and no data has been transferred. The posix()Reasons are from the
platform's network layer. closed means that this socket library knows that the socket is
closed, and invalid() means that something about an argument is invalid.
{error, {Reason, BytesSent}} : An error has been reported but before that some data was
transferred. See {error,Reason} and {ok,BytesSent} above.
sendfile(Socket,FileHandle,Offset,Count,
Timeout :: integer() >= 0) ->
{ok, BytesSent} |
{error, Reason | timeout} |
{error, {Reason | timeout, BytesSent}}
Types:
Socket = socket()
FileHandle = file:fd()
Offset = integer()
Count = BytesSent = integer() >= 0
Reason = posix() | closed | invalid()
Sends file data on a socket, waiting at most Timeout milliseconds for it to be sent (limitedtime-out).
The same as "infinite" time-out sendfile/5 but returns {error,timeout} or {error,{timeout,BytesSent}} after Timeout milliseconds, if not all file data was transferred by the platform's
network layer.
sendfile(Socket,FileHandle,Offset,Count,
SelectHandle :: nowait) ->
{ok, BytesSent} |
{select, SelectInfo} |
{select, {SelectInfo, BytesSent}} |
{error, Reason}
sendfile(Socket,FileHandle,Offset,Count,
SelectHandle :: select_handle()) ->
{ok, BytesSent} |
{select, SelectInfo} |
{select, {SelectInfo, BytesSent}} |
{error, Reason}
Types:
Socket = socket()
FileHandle = file:fd()
Offset = integer()
Count = BytesSent = integer() >= 0
SelectInfo = select_info()
Reason = posix() | closed | invalid()
Sends file data on a socket, but returns a select continuation if the data could not be sent
immediately (nowait).
The same as "infinite" time-out sendfile/5 but if the data is not immediately accepted by the
platform network layer, the function returns {select,SelectInfo}, and the caller will then
receive a select message, {'$socket',Socket,select,SelectHandle} ( with the SelectHandle that
was contained in the SelectInfo ) when there is room for more data. Then a call to sendfile/3 with
SelectInfo as the second argument will continue the data transfer.
If SelectHandle is a select_handle(), that term will be contained in a returned SelectInfo and the
corresponding select message. The SelectHandle is presumed to be unique to this call.
If SelectHandle is nowait, and a SelectInfo is returned, it will contain a select_handle()
generated by the call.
If some file data was sent, the function will return {ok,{BytesSent,SelectInfo}. If the caller
does not want to wait to send the rest of the data, it should immediately cancel the operation
with cancel/2.
sendfile(Socket,Cont,Offset,Count,Timeout::infinity)->
{ok, BytesSent} |
{error, Reason} |
{error, {Reason, BytesSent}}
sendfile(Socket,Cont,Offset,Count,
Timeout :: integer() >= 0) ->
{ok, BytesSent} |
{error, Reason | timeout} |
{error, {Reason | timeout, BytesSent}}
sendfile(Socket,Cont,Offset,Count,SelectHandle::nowait)->
{ok, BytesSent} |
{select, SelectInfo} |
{select, {SelectInfo, BytesSent}} |
{error, Reason}
sendfile(Socket,Cont,Offset,Count,
SelectHandle :: select_handle()) ->
{ok, BytesSent} |
{select, SelectInfo} |
{select, {SelectInfo, BytesSent}} |
{error, Reason}
Types:
Socket = socket()
Cont = select_info()
Offset = integer()
Count = BytesSent = integer() >= 0
SelectInfo = select_info()
Reason = posix() | closed | invalid()
Continues sending file data on a socket, where the send operation was initiated by sendfile/3,5
that returned a SelectInfo continuation. Otherwise like "infinite" time-out sendfile/5 , limited
time-out sendfile/5 or nowait sendfile/5 respectively.
Cont is the SelectInfo that was returned from the previous sendfile() call.
The return value indicates the result from the platform's network layer. See "infinite" time-out
sendfile/5.
sendfile(Socket,FileHandle,Offset,Count)->Result
Types:
Socket = socket()
FileHandle = file:fd()
Offset = integer()
Count = integer() >= 0
The same as sendfile(Socket,FileHandle,Offset,Count,infinity), that is: send the file data
at Offset and Count to the socket, without time-out other than from the platform's network stack.
sendfile(Socket,FileHandle,Timeout)->Result
Types:
Socket = socket()
FileHandle = file:fd()
Timeout = timeout() | 'nowait' | select_handle()
Depending on the Timeout argument; the same as sendfile(Socket,FileHandle,0,0,infinity),sendfile(Socket,FileHandle,0,0,Timeout), or sendfile(Socket,FileHandle,0,0,SelectHandle), that is: send all data in the file to the socket, with the given Timeout.
sendfile(Socket,FileHandle)->Result
Types:
Socket = socket()
FileHandle = file:fd()
The same as sendfile(Socket,FileHandle,0,0,infinity), that is: send all data in the file to
the socket, without time-out other than from the platform's network stack.
setopt(Socket::socket(),
SocketOption :: {Level :: otp, Opt :: otp_socket_option()},
Value :: term()) ->
ok | {error, invalid() | closed}
Sets a socket option in the protocol level otp, which is this implementation's level above the OS
protocol layers.
See the type otp_socket_option() for a description of the options on this level.
setopt(Socket::socket(),
SocketOption :: socket_option(),
Value :: term()) ->
ok | {error, posix() | invalid() | closed}
Set a socket option in one of the OS's protocol levels. See the type socket_option() for which
options that this implementation knows about, how they are related to option names in the OS, and
if there are known pecularities with any of them.
What options are valid depends on what kind of socket it is (domain(), type() and protocol()).
See the socket options chapter of the users guide for more info.
Note:
Not all options are valid, nor possible to set, on all platforms. That is, even if "we" support an
option; it does not mean that the underlying OS does.
setopt(Socket,Level,Opt,Value)->ok|{error,Reason}
Types:
Socket = socket()
Value = term()
Reason = inet:posix() | invalid() | closed
Backwards compatibility function.
The same as setopt(Socket,{Level,Opt},Value)setopt_native(Socket::socket(),
SocketOption ::
socket_option() |
{Level :: level() | (NativeLevel :: integer()),
NativeOpt :: integer()},
Value :: native_value()) ->
ok | {error, posix() | invalid() | closed}
Sets a socket option that may be unknown to our implementation, or that has a type not compatible
with our implementation, that is; in "native mode".
If Value is an integer() it will be used as a C type (int), if it is a boolean() it will be used
as a C type (int) with the C implementations values for false or true, and if it is a binary() its
content and size will be used as the option value.
The socket option may be specified with an ordinary socket_option() tuple, with a known Level=level() and an integer NativeOpt, or with both an integer NativeLevel and NativeOpt.
What options are valid depends on what kind of socket it is (domain(), type() and protocol()).
The integer values for NativeLevel and NativeOpt as well as the encoding of Value has to be
deduced from the header files for the running system.
shutdown(Socket,How)->ok|{error,Reason}
Types:
Socket = socket()
How = read | write | read_write
Reason = posix() | closed
Shut down all or part of a full-duplex connection.
sockname(Socket)->{ok,SockAddr}|{error,Reason}
Types:
Socket = socket()
SockAddr = sockaddr_recv()
Reason = posix() | closed
Returns the current address to which the socket is bound.
supports()->
[{Key1 :: term(),
boolean() |
[{Key2 :: term(),
boolean() | [{Key3 :: term(), boolean()}]}]}]
supports(Key1::term())->
[{Key2 :: term(),
boolean() | [{Key3 :: term(), boolean()}]}]
supports(Key1::term(),Key2::term())->
[{Key3 :: term(), boolean()}]
These functions function retreives information about what the platform supports, such which
platform features or which socket options, are supported.
For keys other than the known the empty list is returned, Note that in a future version or on a
different platform there might be more supported items.
supports():
Returns a list of {Key1,supports(Key1)} tuples for every Key1 described in supports/1 and
{Key1,boolean()} tuples for each of the following keys:
sctp:
SCTP support
ipv6:
IPv6 support
local:
Unix Domain sockets support (AF_UNIX|AF_LOCAL)
netns:
Network Namespaces support (Linux, setns(2))
sendfile:
Sendfile support (sendfile(2))
supports(msg_flags=Key1):
Returns a list of {Flag,boolean()} tuples for every Flag in msg_flag() with the boolean()
indicating if the flag is supported on this platform.
supports(protocols=Key1):
Returns a list of {Name::atom(),boolean()} tuples for every Name in protocol() with the
boolean() indicating if the protocol is supported on this platform.
supports(options=Key1):
Returns a list of {SocketOption,boolean()} tuples for every SocketOption in socket_option()
with the boolean() indicating if the socket option is supported on this platform.
supports(options = Key1, Key2) : For a Key2 in level() returns a list of {Opt,boolean()}
tuples for all known socket options Opt on that Level=:=Key2, and the boolean() indicating
if the socket option is supported on this platform. See setopt/3 and getopt/2.
use_registry(D::boolean())->ok
Globally change if the socket registry is to be used or not. Note that its still possible to
override this explicitly when creating an individual sockets, see open/2 or open/4 for more info
(use the Extra argument).
which_sockets()->[socket()]which_sockets(FilterRule)->[socket()]
Types:
FilterRule =
inet | inet6 | local | stream | dgram | seqpacket | sctp |
tcp | udp |
pid() |
fun((socket_info()) -> boolean())
Returns a list of all sockets, according to the filter rule.
There are several pre-made filter rule(s) and one general:
inet|inet6:
Selection based on the domain of the socket.
Only a subset is valid.
stream|dgram|seqpacket:
Selection based on the type of the socket.
Only a subset is valid.
sctp|tcp|udp:
Selection based on the protocol of the socket.
Only a subset is valid.
pid():
Selection base on which sockets has this pid as Controlling Process.
fun((socket_info())->boolean()):
The general filter rule.
A fun that takes the socket info and returns a boolean() (true if the socket sould be included
and false if should not).