The Linux Programming Interface

(nextflipdebug5) #1
Sockets: Advanced Topics 1283

advanced features such as flow control and congestion control are also required,
then it is probably best to use TCP instead. Trying to implement all of these features
on top of UDP is complex, and, even when well implemented, the result is unlikely
to perform better than TCP.

61.13 Advanced Features


UNIX and Internet domain sockets have many other features that we have not
detailed in this book. We summarize a few of these features in this section. For full
details, see [Stevens et al., 2004].

61.13.1 Out-of-Band Data


Out-of-band data is a feature of stream sockets that allows a sender to mark trans-
mitted data as high priority; that is, the receiver can obtain notification of the avail-
ability of out-of-band data without needing to read all of the intervening data in the
stream. This feature is used in programs such as telnet, rlogin, and ftp to make it possible
to abort previously transmitted commands. Out-of-band data is sent and received
using the MSG_OOB flag in calls to send() and recv(). When a socket receives notification
of the availability of out-of-band data, the kernel generates the SIGURG signal for the
socket owner (normally the process using the socket), as set by the fcntl() F_SETOWN
operation.
When employed with TCP sockets, at most 1 byte of data may be marked as
being out-of-band at any one time. If the sender transmits an additional byte of out-
of-band data before the receiver has processed the previous byte, then the indica-
tion for the earlier out-of-band byte is lost.

TCP’s limitation of out-of-band data to a single byte is an artifact of the mis-
match between the generic out-of-band model of the sockets API and its spe-
cific implementation using TCP’s urgent mode. We touched on TCP’s urgent
mode when looking at the format of TCP segments in Section 61.6.1. TCP
indicates the presence of urgent (out-of-band) data by setting the URG bit in
the TCP header and setting the urgent pointer field to point to the urgent
data. However, TCP has no way of indicating the length of an urgent data
sequence, so the urgent data is considered to consist of a single byte.
Further information about TCP urgent data can be found in RFC 793.

Under some UNIX implementations, out-of-band data is supported for UNIX
domain stream sockets. Linux doesn’t support this.
The use of out-of-band data is nowadays discouraged, and it may be unreliable in
some circumstances (see [Gont & Yourtchenko, 2009]). An alternative is to maintain
a pair of stream sockets for communication. One of these is used for normal commu-
nication, while the other is used for high-priority communication. An application
can monitor both channels using one of the techniques described in Chapter 63.
This approach allows multiple bytes of priority data to be transmitted. Furthermore,
it can be employed with stream sockets in any communication domain (e.g., UNIX
domain sockets).
Free download pdf