Sortix cross-volatile manual
This manual documents Sortix cross-volatile. You can instead view this document in the latest official manual.
NAME
tcp — transmission control protocolSYNOPSIS
#include <sys/socket.h>#include <netinet/in.h>
#include <netinet/tcp.h>
socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
DESCRIPTION
The Transmission Control Protocol (TCP) is a connection-oriented transport layer for the Internet Protocol ip(4) that provides a reliable byte stream connection between two hosts. It is designed for packet-switched networks and provides sequenced data, retransmissions on packet loss, handling of duplicated packets, flow control, basic data integrity checks, multiplexing with a 16-bit port number, support for out-of-band urgent data, and detection of lost connection. TCP provides the SOCK_STREAM abstraction for the inet(4) protocol family.SOCKET OPTIONS
TCP sockets support these setsockopt(2) / getsockopt(2) options at level SOL_SOCKET:- SO_BINDTODEVICE char[]
- Bind to a network interface by its name. (Described in if(4))
- SO_BINDTOINDEX unsigned int
- Bind to a network interface by its index number. (Described in if(4))
- SO_DEBUG int
- Whether the socket is in debug mode. This option is not implemented and is initially 0. Attempting to set it to non-zero will fail with EPERM. (Described in if(4))
- SO_DOMAIN sa_family_t
- The socket domain (the address family). This option can only be read. (Described in if(4))
- SO_ERROR int
- The asynchronous pending error (an errno(3) value). Errors are permanent. This option can only be read. (Described in if(4))
- SO_PROTOCOL int
- The socket protocol (IPPROTO_TCP). This option can only be read. (Described in if(4))
- SO_RCVBUF int
- How many bytes the receive queue can use (default is 64 KiB). (Described in if(4))
- SO_REUSEADDR int
- Whether binding to the any address on a port doesn't conflict with binding to another address and the same port, if both sockets have this option set and the user binding the second socket is the same that bound the first socket or the user binding the second socket has superuser privileges. (Described in if(4))
- SO_SNDBUF int
- How many bytes the send queue can use (default is 64 KiB). (Described in if(4))
- SO_TYPE int
- The socket type (SOCK_STREAM). This option can only be read. (Described in if(4))
IMPLEMENTATION NOTES
Connections time out when a segment has not been acknowledged by the remote socket after 6 attempts to deliver the segment. Each retransmission happens after 1 second plus 1 second per failed transmissions so far. Successful delivery of any segment resets the retransmission count to 0.ERRORS
Socket operations can fail due to these error conditions, in addition to the error conditions of the network and link layer, and the error conditions of the invoked function.- [EADDRINUSE]
- The socket cannot be bound to the requested address and port because another socket was already bound to 1) the same address and port 2) the any address and the same port (and SO_REUSEADDR was not set on both sockets), or 3) some address and the same port but the requested address was the any address (and SO_REUSEADDR was not set on both sockets).
- [EADDRNOTAVAIL]
- The socket cannot be bound to the requested address because no network interface had that address or broadcast address.
- [EADDRNOTAVAIL]
- The socket was connected to port 0.
- [EAGAIN]
- A port could not be assigned because each port in the dynamic port range had already been bound to a socket in a conflicting manner.
- [ECONNREFUSED]
- The destination host refused the connection.
- [ECONNRESET]
- The connection was reset by the remote socket.
- [EHOSTDOWN]
- The destination host is not up. This error can happen asynchronously.
- [EHOSTUNREACH]
- The destination host was unreachable. This error can happen asynchronously.
- [ENETDOWN]
- The network interface isn't up. This error can happen asynchronously.
- [ENETUNREACH]
- The destination network was unreachable. This error can happen asynchronously.
- [ENETUNREACH]
- The remote address could not be connected because there was no route from the local address to the remote address.
- [ENOBUFS]
- There was not enough memory available for network packets.
- [EPERM]
- The unimplemented SO_DEBUG socket options was attempted to be set to a non-zero value.
- [EPIPE]
- The transmission failed because the connetion is broken. The SIGPIPE signal is sent as well unless disabled.
- [ETIMEDOUT]
- The connection timed out delivering a segment. This error can happen asynchronously.