Linux Programming Interface
What is a connection, concretely?
- From RFC 793:
The reliability and flow control mechanisms described above require that TCPs initialize and maintain certain status information for each data stream. The combination of this information, including sockets, sequence numbers, and window sizes, is called a connection. Each connection is uniquely specified by a pair of sockets identifying its two sides.
What does a domain socket file look like from another OS reading off the same drive?
Syscalls (technically glibc functions wrapping a single syscall)
socket()to create a socket
bind()it to an address
listen()on that address
connect()to a bound socket
bindneeds an address, but each type of socket uses a different address format.
sockaddrstruct serves as a generic cast destination for each domain-specific addr struct
backlogargument controls the number of unaccepted connections the kernel buffers before blocking clients attempting to
The key point to understand about accept() is that it creates a new socket, and it is this new socket that is connected to the peer socket that performed the connect(). A file descriptor for the connected socket is returned as the function result of the accept() call. The listening socket (sockfd) remains open, and can be used to accept further connections.
Comm over a socket with
EOFindicates that the socket has been closed
Byte stream that doesn’t respect message boundaries, so a reader might read different “chunks” than were written.
UDP uses a different API:
- UDP sockets can use
connectto have the kernel remember it’s peer on the other end, which allows the use of
write. This isn’t a real connection, though.
Although UNIX domain sockets are identified by pathnames, I/O on these sockets doesn’t involve operations on the underlying device.
for UNIX domain sockets, datagram transmission is carried out within the kernel, and is reliable. All messages are delivered in order and unduplicated.
- Datagrams respect boundaries, so a read always corresponds to a specific write.
socketpair can be used to create two sockets that are connected to each other. Seems like a way to create an internal pipe without requiring a pathname.
TCP allows for out-of-band transmission, where (at most a single byte at a time) data can be marked urgent, and can be processed without having to go through intervening data. Used for aborts, etc. The urgent pointer is related to this.
TCP_NODELAY both buffer data before sending. CORK waits until a target buffer capacity is reached.
NODELAY (Nagle) waits for an ACK.