Lely core libraries 2.3.4
sock.h File Reference

This header file is part of the I/O library; it contains the network socket declarations. More...

#include <lely/io/io.h>
Include dependency graph for sock.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  { IO_SOCK_BTH = 1 , IO_SOCK_IPV4 , IO_SOCK_IPV6 , IO_SOCK_UNIX }
 
enum  { IO_SOCK_STREAM = 1 , IO_SOCK_DGRAM }
 
enum  { IO_MSG_PEEK = 1 << 0 , IO_MSG_OOB = 1 << 1 , IO_MSG_WAITALL = 1 << 2 }
 
enum  { IO_SHUT_RD , IO_SHUT_WR , IO_SHUT_RDWR }
 

Functions

io_handle_t io_open_socket (int domain, int type)
 Opens a network socket. More...
 
int io_open_socketpair (int domain, int type, io_handle_t handle_vector[2])
 Opens a pair of connected sockets. More...
 
ssize_t io_recv (io_handle_t handle, void *buf, size_t nbytes, io_addr_t *addr, int flags)
 Performs a receive operation on a network socket. More...
 
ssize_t io_send (io_handle_t handle, const void *buf, size_t nbytes, const io_addr_t *addr, int flags)
 Performs a send operation on a network socket. More...
 
io_handle_t io_accept (io_handle_t handle, io_addr_t *addr)
 Accepts an incoming connection on a listening socket. More...
 
int io_connect (io_handle_t handle, const io_addr_t *addr)
 Connects a socket to a network address. More...
 
int io_sock_get_domain (io_handle_t handle)
 Obtains the domain of a socket (the first parameter in a call to io_open_socket() or io_open_socketpair()). More...
 
int io_sock_get_type (io_handle_t handle)
 Obtains the type of a network socket (the second parameter in a call to io_open_socket() or io_open_socketpair()). More...
 
int io_sock_bind (io_handle_t handle, const io_addr_t *addr)
 Binds a local network address to a socket. More...
 
int io_sock_listen (io_handle_t handle, int backlog)
 Marks a connection-mode socket (IO_SOCK_STREAM) as accepting connections. More...
 
int io_sock_shutdown (io_handle_t handle, int how)
 Causes all or part of a full-duplex connection on a socket to be shut down. More...
 
int io_sock_get_sockname (io_handle_t handle, io_addr_t *addr)
 Obtains the locally-bound name of a socket and stores the resulting address in *addr. More...
 
int io_sock_get_peername (io_handle_t handle, io_addr_t *addr)
 Obtains the peer address of a socket and stores the result in *addr. More...
 
int io_sock_get_maxconn (void)
 Returns the maximum queue length for pending connections. More...
 
int io_sock_get_acceptconn (io_handle_t handle)
 Checks if a socket is currently listening for incoming connections. More...
 
int io_sock_get_broadcast (io_handle_t handle)
 Checks if a socket is allowed to send broadcast messages. More...
 
int io_sock_set_broadcast (io_handle_t handle, int broadcast)
 Enables a socket to send broadcast messages if broadcast is non-zero, and disables this option otherwise (disabled by default). More...
 
int io_sock_get_debug (io_handle_t handle)
 Checks if debugging is enabled for a socket. More...
 
int io_sock_set_debug (io_handle_t handle, int debug)
 Enables (platform dependent) debugging output for a socket if debug is non-zero, and disables this option otherwise (disabled by default). More...
 
int io_sock_get_dontroute (io_handle_t handle)
 Checks if routing is disabled for a socket. More...
 
int io_sock_set_dontroute (io_handle_t handle, int dontroute)
 Bypasses normal routing for a socket if dontroute is non-zero, and disables this option otherwise (disabled by default). More...
 
int io_sock_get_error (io_handle_t handle, int *perror)
 Obtains and clears the current error number of a socket, and stores the value in *perror. More...
 
int io_sock_get_keepalive (io_handle_t handle)
 Checks if the TCP keep-alive option is enabled for a socket. More...
 
int io_sock_set_keepalive (io_handle_t handle, int keepalive, int time, int interval)
 Enables or disables the TCP keep-alive option for a socket (disabled by default). More...
 
int io_sock_get_linger (io_handle_t handle)
 Obtains the linger time (in seconds) of a socket. More...
 
int io_sock_set_linger (io_handle_t handle, int time)
 Sets the time (in seconds) io_close() will wait for unsent messages to be sent. More...
 
int io_sock_get_oobinline (io_handle_t handle)
 Checks if out-of-band data is received in the normal data stream of a socket. More...
 
int io_sock_set_oobinline (io_handle_t handle, int oobinline)
 Requests that out-of-band data is placed into the normal data stream of socket if oobinline is non-zero, and disables this option otherwise (disabled by default). More...
 
int io_sock_get_rcvbuf (io_handle_t handle)
 Obtains the size (in bytes) of the receive buffer of a socket. More...
 
int io_sock_set_rcvbuf (io_handle_t handle, int size)
 Sets the size (in bytes) of the receive buffer of a socket. More...
 
int io_sock_set_rcvtimeo (io_handle_t handle, int timeout)
 Sets the timeout (in milliseconds) of a receive operation on a socket. More...
 
int io_sock_get_reuseaddr (io_handle_t handle)
 Checks if a socket is allowed to be bound to an address that is already in use. More...
 
int io_sock_set_reuseaddr (io_handle_t handle, int reuseaddr)
 Enables a socket to be bound to an address that is already in use if reuseaddr is non-zero, and disables this option otherwise (disabled by default). More...
 
int io_sock_get_sndbuf (io_handle_t handle)
 Obtains the size (in bytes) of the send buffer of a socket. More...
 
int io_sock_set_sndbuf (io_handle_t handle, int size)
 Sets the size (in bytes) of the send buffer of a socket. More...
 
int io_sock_set_sndtimeo (io_handle_t handle, int timeout)
 Sets the timeout (in milliseconds) of a send operation on a socket. More...
 
int io_sock_get_tcp_nodelay (io_handle_t handle)
 Checks if Nagle's algorithm for send coalescing is enabled for a socket. More...
 
int io_sock_set_tcp_nodelay (io_handle_t handle, int nodelay)
 Disables Nagle's algorithm for send coalescing if nodelay is non-zero, and enables it otherwise. More...
 
ssize_t io_sock_get_nread (io_handle_t handle)
 Obtains the amount of data (in bytes) in the input buffer of a socket. More...
 
int io_sock_get_mcast_loop (io_handle_t handle)
 Checks if the loopback of outgoing multicast datagrams is enabled for a socket. More...
 
int io_sock_set_mcast_loop (io_handle_t handle, int loop)
 Enables the loopback of outgoing multicast datagrams for a socket if loop is non-zero, and disables this option otherwise (enabled by default). More...
 
int io_sock_get_mcast_ttl (io_handle_t handle)
 Obtains the TTL (time to live) value for IP multicast traffic on a socket. More...
 
int io_sock_set_mcast_ttl (io_handle_t handle, int ttl)
 Sets the TTL (time to live) value for IP multicast traffic on a socket (the default is 1). More...
 
int io_sock_mcast_join_group (io_handle_t handle, unsigned int index, const io_addr_t *group)
 Joins an any-source multicast group. More...
 
int io_sock_mcast_block_source (io_handle_t handle, unsigned int index, const io_addr_t *group, const io_addr_t *source)
 Blocks data from a given source to a given multicast group. More...
 
int io_sock_mcast_unblock_source (io_handle_t handle, unsigned int index, const io_addr_t *group, const io_addr_t *source)
 Unblocks data from a given source to a given multicast group. More...
 
int io_sock_mcast_leave_group (io_handle_t handle, unsigned int index, const io_addr_t *group)
 Leaves an any-source multicast group. More...
 
int io_sock_mcast_join_source_group (io_handle_t handle, unsigned int index, const io_addr_t *group, const io_addr_t *source)
 Joins a source-specific multicast group. More...
 
int io_sock_mcast_leave_source_group (io_handle_t handle, unsigned int index, const io_addr_t *group, const io_addr_t *source)
 Leaves a source-specific multicast group. More...
 

Detailed Description

This header file is part of the I/O library; it contains the network socket declarations.

Author
J. S. Seldenthuis jseld.nosp@m.enth.nosp@m.uis@l.nosp@m.ely..nosp@m.com

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Definition in file sock.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
IO_SOCK_BTH 

A Bluetooth socket.

IO_SOCK_IPV4 

An IPv4 socket.

IO_SOCK_IPV6 

An IPv6 socket.

IO_SOCK_UNIX 

A UNIX domain socket (only supported on POSIX platforms).

Definition at line 27 of file sock.h.

◆ anonymous enum

anonymous enum
Enumerator
IO_SOCK_STREAM 

A stream-oriented connection-mode socket type.

This corresponds to TCP for IPv4 or IPv6 sockets and RFCOMM for Bluetooth.

IO_SOCK_DGRAM 

A datagram-oriented, typically connectionless-mode, socket type.

This corresponds to UDP for IPv4 or IPv6 sockets.

Definition at line 38 of file sock.h.

◆ anonymous enum

anonymous enum
Enumerator
IO_MSG_PEEK 

Peeks at incoming data.

IO_MSG_OOB 

Requests out-of-band data.

IO_MSG_WAITALL 

On stream-oriented sockets, block until the full amount of data can be returned.

Definition at line 51 of file sock.h.

◆ anonymous enum

anonymous enum
Enumerator
IO_SHUT_RD 

Disables further receive operations.

IO_SHUT_WR 

Disables further send operations.

IO_SHUT_RDWR 

Disables further send and receive operations.

Definition at line 63 of file sock.h.

Function Documentation

◆ io_open_socket()

io_handle_t io_open_socket ( int  domain,
int  type 
)

Opens a network socket.

Parameters
domainthe domain of the socket (one of IO_SOCK_BTH, IO_SOCK_IPV4, IO_SOCK_IPV6 or IO_SOCK_UNIX).
typethe type of the socket (either IO_SOCK_STREAM or IO_SOCK_DGRAM).
Returns
a new I/O device handle, or IO_HANDLE_ERROR on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 78 of file sock.c.

◆ io_open_socketpair()

int io_open_socketpair ( int  domain,
int  type,
io_handle_t  handle_vector[2] 
)

Opens a pair of connected sockets.

Parameters
domainthe domain of the sockets (one of IO_SOCK_IPV4, IO_SOCK_IPV6 or IO_SOCK_UNIX).
typethe type of the sockets (either IO_SOCK_STREAM or IO_SOCK_DGRAM).
handle_vectora 2-value array which, on success, contains the device handles of the socket pair.
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 185 of file sock.c.

◆ io_recv()

ssize_t io_recv ( io_handle_t  handle,
void *  buf,
size_t  nbytes,
io_addr_t addr,
int  flags 
)

Performs a receive operation on a network socket.

Parameters
handlea valid socket device handle.
bufa pointer to the destination buffer.
nbytesthe number of bytes to receive.
addran optional pointer to a value which, on success, contains the source address.
flagsthe type of message reception (any combination of IO_MSG_PEEK, IO_MSG_OOB and IO_MSG_WAITALL).
Returns
the number of bytes received on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 305 of file sock.c.

◆ io_send()

ssize_t io_send ( io_handle_t  handle,
const void *  buf,
size_t  nbytes,
const io_addr_t addr,
int  flags 
)

Performs a send operation on a network socket.

Parameters
handlea valid socket device handle.
bufa pointer to the source buffer.
nbytesthe number of bytes to send.
addran optional pointer to the destination address (ignored for connection-mode sockets).
flagstype type of message transmission (0 or IO_MSG_OOB).
Returns
the number of bytes sent on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 323 of file sock.c.

◆ io_accept()

io_handle_t io_accept ( io_handle_t  handle,
io_addr_t addr 
)

Accepts an incoming connection on a listening socket.

Parameters
handlea valid socket device handle.
addran optional pointer to a value which, on success, contains the incoming network address.
Returns
a new I/O device handle, or IO_HANDLE_ERROR on error. In the latter case, the error number can be obtained with get_errc().
See also
io_sock_listen()

Definition at line 341 of file sock.c.

◆ io_connect()

int io_connect ( io_handle_t  handle,
const io_addr_t addr 
)

Connects a socket to a network address.

Parameters
handlea valid socket device handle.
addra pointer to the network address to which to connect.
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 358 of file sock.c.

◆ io_sock_get_domain()

int io_sock_get_domain ( io_handle_t  handle)

Obtains the domain of a socket (the first parameter in a call to io_open_socket() or io_open_socketpair()).

Returns
IO_SOCK_BTH, IO_SOCK_IPV4, IO_SOCK_IPV6 or IO_SOCK_UNIX, or -1 on error. In the latter case, the error number can be obtained with get_errc().
See also
io_sock_get_type(), io_addr_get_domain()

Definition at line 377 of file sock.c.

◆ io_sock_get_type()

int io_sock_get_type ( io_handle_t  handle)

Obtains the type of a network socket (the second parameter in a call to io_open_socket() or io_open_socketpair()).

Returns
IO_SOCK_STREAM or IO_SOCK_DGRAM, or -1 on error. In the latter case, the error number can be obtained with get_errc().
See also
io_sock_get_domain()

Definition at line 393 of file sock.c.

◆ io_sock_bind()

int io_sock_bind ( io_handle_t  handle,
const io_addr_t addr 
)

Binds a local network address to a socket.

Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 409 of file sock.c.

◆ io_sock_listen()

int io_sock_listen ( io_handle_t  handle,
int  backlog 
)

Marks a connection-mode socket (IO_SOCK_STREAM) as accepting connections.

Parameters
handlea valid socket device handle.
backlogthe number of pending connections in the socket's listen queue. The maximum value can be obtained with io_sock_get_maxconn(). If backlog is 0, an implementation-defined minimum value is used.
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().
See also
io_accept()

Definition at line 423 of file sock.c.

◆ io_sock_shutdown()

int io_sock_shutdown ( io_handle_t  handle,
int  how 
)

Causes all or part of a full-duplex connection on a socket to be shut down.

Parameters
handlea valid socket device handle.
howthe type of shutdown (one of IO_SHUT_RD, IO_SHUT_WR or IO_SHUT_RDWR).
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 434 of file sock.c.

◆ io_sock_get_sockname()

int io_sock_get_sockname ( io_handle_t  handle,
io_addr_t addr 
)

Obtains the locally-bound name of a socket and stores the resulting address in *addr.

The socket name is set by io_sock_bind() and io_connect().

Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 470 of file sock.c.

◆ io_sock_get_peername()

int io_sock_get_peername ( io_handle_t  handle,
io_addr_t addr 
)

Obtains the peer address of a socket and stores the result in *addr.

The peer name is set by io_accept() and io_connect().

Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 500 of file sock.c.

◆ io_sock_get_maxconn()

int io_sock_get_maxconn ( void  )

Returns the maximum queue length for pending connections.

This value can be used as the backlog parameter in a call to io_sock_listen().

Returns
the value of SOMAXCONN, or -1 on error.

Definition at line 530 of file sock.c.

◆ io_sock_get_acceptconn()

int io_sock_get_acceptconn ( io_handle_t  handle)

Checks if a socket is currently listening for incoming connections.

This function implements the SOL_SOCKET/SO_ACCEPTCONN option.

Returns
1 if the socket is accepting connections and 0 if not, or -1 on error. In the latter case, the error number can be obtained with get_errc().
See also
io_sock_listen()

Definition at line 536 of file sock.c.

◆ io_sock_get_broadcast()

int io_sock_get_broadcast ( io_handle_t  handle)

Checks if a socket is allowed to send broadcast messages.

This function implements the SOL_SOCKET/SO_BROADCAST option.

Returns
1 if address reuse is enabled and 0 if not, or -1 on error. In the latter case, the error number can be obtained with get_errc().
See also
io_sock_set_broadcast()

Definition at line 557 of file sock.c.

◆ io_sock_set_broadcast()

int io_sock_set_broadcast ( io_handle_t  handle,
int  broadcast 
)

Enables a socket to send broadcast messages if broadcast is non-zero, and disables this option otherwise (disabled by default).

This function implements the SOL_SOCKET/SO_BROADCAST option.

Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().
See also
io_sock_get_broadcast()

Definition at line 578 of file sock.c.

◆ io_sock_get_debug()

int io_sock_get_debug ( io_handle_t  handle)

Checks if debugging is enabled for a socket.

This function implements the SOL_SOCKET/SO_DEBUG option.

Returns
1 if debugging is enabled and 0 if not, or -1 on error. In the latter case, the error number can be obtained with get_errc().
See also
io_sock_set_debug()

Definition at line 597 of file sock.c.

◆ io_sock_set_debug()

int io_sock_set_debug ( io_handle_t  handle,
int  debug 
)

Enables (platform dependent) debugging output for a socket if debug is non-zero, and disables this option otherwise (disabled by default).

This function implements the SOL_SOCKET/SO_DEBUG option.

Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().
See also
io_sock_get_debug()

Definition at line 618 of file sock.c.

◆ io_sock_get_dontroute()

int io_sock_get_dontroute ( io_handle_t  handle)

Checks if routing is disabled for a socket.

This function implements the SOL_SOCKET/SO_DONTROUTE option.

Returns
1 if routing is disabled and 0 if not, or -1 on error. In the latter case, the error number can be obtained with get_errc().
See also
io_sock_set_dontroute()

Definition at line 637 of file sock.c.

◆ io_sock_set_dontroute()

int io_sock_set_dontroute ( io_handle_t  handle,
int  dontroute 
)

Bypasses normal routing for a socket if dontroute is non-zero, and disables this option otherwise (disabled by default).

This function implements the SOL_SOCKET/SO_DONTROUTE option.

Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().
See also
io_sock_get_dontroute()

Definition at line 658 of file sock.c.

◆ io_sock_get_error()

int io_sock_get_error ( io_handle_t  handle,
int *  perror 
)

Obtains and clears the current error number of a socket, and stores the value in *perror.

This function implements the SOL_SOCKET/SO_ERROR option.

Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 677 of file sock.c.

◆ io_sock_get_keepalive()

int io_sock_get_keepalive ( io_handle_t  handle)

Checks if the TCP keep-alive option is enabled for a socket.

This function implements the SOL_SOCKET/KEEPALIVE option.

Returns
1 if TCP keep-alive is enabled and 0 if not, or -1 on error. In the latter case, the error number can be obtained with get_errc().
See also
io_sock_set_keepalive()

Definition at line 692 of file sock.c.

◆ io_sock_set_keepalive()

int io_sock_set_keepalive ( io_handle_t  handle,
int  keepalive,
int  time,
int  interval 
)

Enables or disables the TCP keep-alive option for a socket (disabled by default).

Note that the time and interval options are supported only on Windows and Linux. This function implements the SOL_SOCKET/SO_KEEPALIVE option.

Parameters
handlea valid socket device handle.
keepalivea boolean option specifying whether TCP keep-alive should be enabled (non-zero) or disabled (zero).
timethe timeout (in seconds) after which the first keep-alive packet is sent. This parameter is unused if keepalive is zero.
intervalthe interval (in seconds) between successive keep-alive packets if no acknowledgment is received. This parameter is unused if keepalive is zero.
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().
See also
io_sock_get_keepalive()

Definition at line 713 of file sock.c.

◆ io_sock_get_linger()

int io_sock_get_linger ( io_handle_t  handle)

Obtains the linger time (in seconds) of a socket.

This function implements the SOL_SOCKET/SO_LINGER option.

Returns
the linger time, or -1 on error. In the latter case, the error number can be obtained with get_errc().
See also
io_sock_set_linger()

Definition at line 760 of file sock.c.

◆ io_sock_set_linger()

int io_sock_set_linger ( io_handle_t  handle,
int  time 
)

Sets the time (in seconds) io_close() will wait for unsent messages to be sent.

If time is 0, lingering is disabled. This function implements the SOL_SOCKET/SO_LINGER option.

Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().
See also
io_sock_getlinger()

Definition at line 777 of file sock.c.

◆ io_sock_get_oobinline()

int io_sock_get_oobinline ( io_handle_t  handle)

Checks if out-of-band data is received in the normal data stream of a socket.

This function implements the SOL_SOCKET/SO_OOBINLINE option.

Returns
1 if out-of-band data is received in the normal data stream and 0 if not, or -1 on error. In the latter case, the error number can be obtained with get_errc().
See also
io_sock_set_oobinline()

Definition at line 797 of file sock.c.

◆ io_sock_set_oobinline()

int io_sock_set_oobinline ( io_handle_t  handle,
int  oobinline 
)

Requests that out-of-band data is placed into the normal data stream of socket if oobinline is non-zero, and disables this option otherwise (disabled by default).

This function implements the SOL_SOCKET/SO_OOBINLINE option.

Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().
See also
io_sock_get_oobinline()

Definition at line 818 of file sock.c.

◆ io_sock_get_rcvbuf()

int io_sock_get_rcvbuf ( io_handle_t  handle)

Obtains the size (in bytes) of the receive buffer of a socket.

This function implements the SOL_SOCKET/SO_RCVBUF option.

Returns
the size of the receive buffer, or -1 on error. In the latter case, the error number can be obtained with get_errc().
See also
io_sock_set_rcvbuf()

Definition at line 837 of file sock.c.

◆ io_sock_set_rcvbuf()

int io_sock_set_rcvbuf ( io_handle_t  handle,
int  size 
)

Sets the size (in bytes) of the receive buffer of a socket.

This function implements the SOL_SOCKET/SO_RCVBUF option.

Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().
See also
io_sock_get_rcvbuf()

Definition at line 854 of file sock.c.

◆ io_sock_set_rcvtimeo()

int io_sock_set_rcvtimeo ( io_handle_t  handle,
int  timeout 
)

Sets the timeout (in milliseconds) of a receive operation on a socket.

This function implements the SOL_SOCKET/SO_RCVTIMEO option.

Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 868 of file sock.c.

◆ io_sock_get_reuseaddr()

int io_sock_get_reuseaddr ( io_handle_t  handle)

Checks if a socket is allowed to be bound to an address that is already in use.

This function implements the SOL_SOCKET/SO_REUSEADDR option.

Returns
1 if address reuse is enabled and 0 if not, or -1 on error. In the latter case, the error number can be obtained with get_errc().
See also
io_sock_set_reuseaddr()

Definition at line 888 of file sock.c.

◆ io_sock_set_reuseaddr()

int io_sock_set_reuseaddr ( io_handle_t  handle,
int  reuseaddr 
)

Enables a socket to be bound to an address that is already in use if reuseaddr is non-zero, and disables this option otherwise (disabled by default).

This function implements the SOL_SOCKET/SO_REUSEADDR option.

Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().
See also
io_sock_get_reuseaddr()

Definition at line 909 of file sock.c.

◆ io_sock_get_sndbuf()

int io_sock_get_sndbuf ( io_handle_t  handle)

Obtains the size (in bytes) of the send buffer of a socket.

This function implements the SOL_SOCKET/SO_SNDBUF option.

Returns
the size of the send buffer, or -1 on error. In the latter case, the error number can be obtained with get_errc().
See also
io_sock_set_sndbuf()

Definition at line 928 of file sock.c.

◆ io_sock_set_sndbuf()

int io_sock_set_sndbuf ( io_handle_t  handle,
int  size 
)

Sets the size (in bytes) of the send buffer of a socket.

This function implements the SOL_SOCKET/SO_SNDBUF option.

Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().
See also
io_sock_get_sndbuf()

Definition at line 945 of file sock.c.

◆ io_sock_set_sndtimeo()

int io_sock_set_sndtimeo ( io_handle_t  handle,
int  timeout 
)

Sets the timeout (in milliseconds) of a send operation on a socket.

This function implements the SOL_SOCKET/SO_SNDTIMEO option.

Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 959 of file sock.c.

◆ io_sock_get_tcp_nodelay()

int io_sock_get_tcp_nodelay ( io_handle_t  handle)

Checks if Nagle's algorithm for send coalescing is enabled for a socket.

This function implements the IPPROTO_TCP/TCP_NODELAY option.

Returns
1 if Nagle's algorithm is disabled and 0 otherwise, or -1 on error. In the latter case, the error number can be obtained with get_errc().
See also
io_sock_set_tcp_nodelay()

Definition at line 979 of file sock.c.

◆ io_sock_set_tcp_nodelay()

int io_sock_set_tcp_nodelay ( io_handle_t  handle,
int  nodelay 
)

Disables Nagle's algorithm for send coalescing if nodelay is non-zero, and enables it otherwise.

This function implements the IPPROTO_TCP/TCP_NODELAY option. Nagle's algorithm is enabled by default.

Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().
See also
io_sock_get_tcp_nodelay()

Definition at line 1000 of file sock.c.

◆ io_sock_get_nread()

ssize_t io_sock_get_nread ( io_handle_t  handle)

Obtains the amount of data (in bytes) in the input buffer of a socket.

Returns
the number of bytes that can be read, or -1 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 1020 of file sock.c.

◆ io_sock_get_mcast_loop()

int io_sock_get_mcast_loop ( io_handle_t  handle)

Checks if the loopback of outgoing multicast datagrams is enabled for a socket.

This function implements the IPPROTO_IP/IP_MULTICAST_LOOP and IPPROTO_IPV6/IPV6_MULTICAST_LOOP options.

Returns
1 if multicast loopback is enabled and 0 if not, or -1 on error. In the latter case, the error number can be obtained with get_errc().
See also
io_sock_set_mcast_loop()

Definition at line 1050 of file sock.c.

◆ io_sock_set_mcast_loop()

int io_sock_set_mcast_loop ( io_handle_t  handle,
int  loop 
)

Enables the loopback of outgoing multicast datagrams for a socket if loop is non-zero, and disables this option otherwise (enabled by default).

This function implements the IPPROTO_IP/IP_MULTICAST_LOOP and IPPROTO_IPV6/IPV6_MULTICAST_LOOP options.

Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().
See also
io_sock_get_mcast_loop()

Definition at line 1090 of file sock.c.

◆ io_sock_get_mcast_ttl()

int io_sock_get_mcast_ttl ( io_handle_t  handle)

Obtains the TTL (time to live) value for IP multicast traffic on a socket.

This function implements the IPPROTO_IP/IP_MULTICAST_TTL and IPPROTO_IPV6/IPV6_MULTICAST_HOPS options.

Returns
the TTL for IP multicast traffic, or -1 on error. In the latter case, the error number can be obtained with get_errc().
See also
io_sock_set_mcast_ttl()

Definition at line 1125 of file sock.c.

◆ io_sock_set_mcast_ttl()

int io_sock_set_mcast_ttl ( io_handle_t  handle,
int  ttl 
)

Sets the TTL (time to live) value for IP multicast traffic on a socket (the default is 1).

This function implements the IPPROTO_IP/IP_MULTICAST_TTL and IPPROTO_IPV6/IPV6_MULTICAST_HOPS options.

Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().
See also
io_sock_get_mcast_ttl()

Definition at line 1165 of file sock.c.

◆ io_sock_mcast_join_group()

int io_sock_mcast_join_group ( io_handle_t  handle,
unsigned int  index,
const io_addr_t group 
)

Joins an any-source multicast group.

Parameters
handlea valid IPv4 or IPv6 connectionless socket device handle.
indexa network interface index. On Linux, if index is 0, the interface is chosen automatically.
groupa pointer to the address of the group to join.
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().
See also
io_sock_mcast_leave_group()

Definition at line 1200 of file sock.c.

◆ io_sock_mcast_block_source()

int io_sock_mcast_block_source ( io_handle_t  handle,
unsigned int  index,
const io_addr_t group,
const io_addr_t source 
)

Blocks data from a given source to a given multicast group.

Parameters
handlea valid IPv4 or IPv6 connectionless socket device handle.
indexa network interface index. On Linux, if index is 0, the interface is chosen automatically.
groupa pointer to the address of the multicast group.
sourcea pointer to the address of the source to block.
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().
See also
io_sock_mcast_unblock_source()

Definition at line 1230 of file sock.c.

◆ io_sock_mcast_unblock_source()

int io_sock_mcast_unblock_source ( io_handle_t  handle,
unsigned int  index,
const io_addr_t group,
const io_addr_t source 
)

Unblocks data from a given source to a given multicast group.

Parameters
handlea valid IPv4 or IPv6 connectionless socket device handle.
indexa network interface index. On Linux, if index is 0, the interface is chosen automatically.
groupa pointer to the address of the multicast group.
sourcea pointer to the address of the source to unblock.
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().
See also
io_sock_mcast_block_source()

Definition at line 1262 of file sock.c.

◆ io_sock_mcast_leave_group()

int io_sock_mcast_leave_group ( io_handle_t  handle,
unsigned int  index,
const io_addr_t group 
)

Leaves an any-source multicast group.

Parameters
handlea valid IPv4 or IPv6 connectionless socket device handle.
indexa network interface index. On Linux, if index is 0, the interface is chosen automatically.
groupa pointer to the address of the group to leave.
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().
See also
io_sock_mcast_join_group()

Definition at line 1294 of file sock.c.

◆ io_sock_mcast_join_source_group()

int io_sock_mcast_join_source_group ( io_handle_t  handle,
unsigned int  index,
const io_addr_t group,
const io_addr_t source 
)

Joins a source-specific multicast group.

Parameters
handlea valid IPv4 or IPv6 connectionless socket device handle.
indexa network interface index. On Linux, if index is 0, the interface is chosen automatically.
groupa pointer to the address of the group to join.
sourcea pointer to the address of the source from which to receive data.
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().
See also
io_sock_mcast_join_source_group()

Definition at line 1324 of file sock.c.

◆ io_sock_mcast_leave_source_group()

int io_sock_mcast_leave_source_group ( io_handle_t  handle,
unsigned int  index,
const io_addr_t group,
const io_addr_t source 
)

Leaves a source-specific multicast group.

Parameters
handlea valid IPv4 or IPv6 connectionless socket device handle.
indexa network interface index. On Linux, if index is 0, the interface is chosen automatically.
groupa pointer to the address of the group to leave.
sourcea pointer to the address of the source from which data was received.
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().
See also
io_sock_mcast_leave_source_group()

Definition at line 1356 of file sock.c.