c. 通过设置SO_OOBINLINE 和sockatmark()函数。首先设置SO_OOBINLINE在普通接收缓冲区中接收带外数据。然后程序读取该缓冲区时结合seockatmark检测是否当前位置属于带外数据区。注意,假设这样的而一个缓冲区内容123456x789.其中x为带外数据。read时内核会将123456和x789中间做标记。程序读取到x时会自动停住。然后下次继续读取剩下的(这是通过sockatmark就会发现处于带外数据区,此时如果read(sockfd,buf, 1)的话buf里面就时带外数据了(x).
When an application on a connected stream socket needs to send data that is more important than regular data on the stream, it can mark the important data as out-of-band (OOB) data. The application on the other end of a connection can receive and process OOB data through a separate logical channel that is conceptually independent of the data stream.
In TCP, OOB data is implemented via an urgent 1-bit marker (called URG) and a 16-bit pointer in the TCP segment header that identify a specific downstream byte as urgent data. Two specific ways of implementing urgent data currently exist for TCP. RFC 793, which describes TCP and introduces the concept of urgent data, indicates that the urgent pointer in the TCP header is a positive offset to the byte that follows the urgent data byte. However, RFC 1122 describes the urgent offset as pointing to the urgent byte itself.
The Winsock specification uses the term OOB to refer to both protocol-independent OOB data and TCP's implementation of OOB data (urgent data). To check whether pending data contains urgent data, you must call theioctlsocket function with the SIOCATMARK option. Chapter 7 discusses how to use SIOCATMARK.
Winsock provides several methods for obtaining the urgent data. Either the urgent data is inlined so that it appears in the normal data stream, or inlining can be turned off so that a discrete call to a receive function returns only the urgent data. The socket option SO_OOBINLINE, also discussed in detail in Chapter 7, controls the behavior of OOB data.
Telnet and Rlogin use urgent data for several reasons. However, unless you plan to write your own Telnet or Rlogin, you should stay away from urgent data. It's not well defined and might be implemented differently on platforms other than Windows. If you require a method of signaling the peer for urgent reasons, implement a separate control socket for this urgent data and reserve the main socket connection for normal data transfers.