The TCP - CORK

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

When the TCP_CORK option is enabled on a TCP socket, all subsequent output is buffered into a single

TCP segment until either the upper limit on the size of a segment is reached, the TCP_CORK option is
disabled, the socket is closed, or a maximum of 200 milliseconds passes from the time that the first
corked byte is written. (The timeout ensures that the corked data is transmitted if the application forgets
to disable the TCP_CORK option.) We enable and disable the TCP_CORK option using the setsockopt()
system call (Section 61.9). The following code (which omits error checking) demonstrates the use of
TCP_CORK for our hypothetical HTTP server example: For both calls, sockfd is a file descriptor referring
to a socket, and addr is a pointer to a suitably sized buffer that is used to return a structure containing
the socket address. The size and type of this structure depend on the socket domain. The addrlen
argument is a value-result argument. Before the call, it should be initialized to the length of the buffer
pointed to by addr; on return, it contains the number of bytes actually written to this buffer. The
getsockname() function returns a socket’s address family and the address to which a socket is bound.
This is useful if the socket was bound by another program (e.g., inetd(8)) and the socket file descriptor
was then preserved across an exec(). Calling getsockname() is also useful if we want to determine the
ephemeral port number that the kernel assigned to a socket when performing an implicit bind of an
Internet domain socket. The kernel performs an implicit bind in the following circumstances: z after a
connect() or a listen() call on a TCP socket that has not previously been bound to an address by bind(); z
on the first sendto() on a UDP socket that had not previously been bound to an address; or z after a
bind() call where the port number (sin_port) was specified as 0. In this case, the bind() specifies the IP
address for the socket, but the kernel selects an ephemeral port number.

You might also like