ptg10805159
626 Network IPC: Sockets Chapter 16
16.7 Out-of-Band Data
Out-of-band data is an optional featuresupported by some communication protocols,
allowing higher-priority delivery of data than normal. Out-of-band data is sent ahead
of any data that is already queued for transmission. TCP supports out-of-band data,
but UDP doesn’t. The socket interface to out-of-band data is heavily influenced by
TCP’s implementation of out-of-band data.
TCP refers to out-of-band data as ‘‘urgent’’data. TCP supports only a single byte of
urgent data, but allows urgent data to be delivered out of band from the normal data
delivery mechanisms. To generate urgent data, we specify theMSG_OOBflag to any of
the threesendfunctions. If we send morethan one byte with theMSG_OOBflag, the last
byte will be treated as the urgent-data byte.
When urgent data is received, we aresent theSIGURGsignal if we have arranged
for signal generation by the socket. In Sections 3.14 and 14.5.2, we saw that we could
use theF_SETOWNcommand tofcntlto set the ownership of a socket. If the third
argument tofcntlis positive, it specifies a process ID. If it is a negative value other
than−1, it represents the process group ID. Thus, we can arrange that our process
receive signals from a socket by calling
fcntl(sockfd, F_SETOWN, pid);
TheF_GETOWNcommand can be used to retrieve the current socket ownership. As
with theF_SETOWNcommand, a negative value represents a process group ID and a
positive value represents a process ID. Thus, the call
owner = fcntl(sockfd, F_GETOWN, 0);
will return withownerequal to the ID of the process configured to receive signals from
the socket ifowneris positive and with the absolute value ofownerequal to the ID of
the process group configured to receive signals from the socket ifowneris negative.
TCP supports the notion of anurgent mark:the point in the normal data stream
wherethe urgent data would go. We can choose to receive the urgent data inline with
the normal data if we use theSO_OOBINLINEsocket option.To help us identify when
we have reached the urgent mark, we can use thesockatmarkfunction.
#include <sys/socket.h>
int sockatmark(intsockfd);
Returns: 1 if at mark, 0 if not at mark,−1 on error
When the next byte to be read is at the urgent mark,sockatmarkwill return 1.
When out-of-band data is present in a socket’s read queue, theselectfunction
(Section 14.4.1) will return the file descriptor as having an exception condition pending.
We can choose to receive the urgent data inline with the normal data, or we can use the
MSG_OOBflag with one of therecvfunctions to receive the urgent data ahead of any
other queue data. TCP queues only one byte of urgent data. If another urgent byte
arrives before we receive the current one, the existing one is discarded.