Out-of-Band (OOB) Data

 < Day Day Up > 



Out-of-band (or OOB) data is a stream socket abstraction that creates the concept of a dual stream for communication over a pair of sockets. This secondary stream is a logically independent stream of data that can be used for signaling outside of the transfer of regular data. As the regular data stream and the OOB data stream are independent, the Sockets API must provide a way for the application to specify which of the streams should be manipulated. This specification is provided through the MSG_OOB flag of the send/recv and sendto/recvfrom Sockets API functions. For example:

ret = send( sock, buffer, len, MSG_OOB ); ret = recv( sock, buffer, len, MSG_OOB );

For the send function, the MSG_OOB flag defines that the data in buffer is out-of-band data. Conversely, with the recv function, the MSG_OOB flag specifies that receipt of out-of-band data be requested.

With the TCP protocol, only one byte of data may be transferred as out-of-band at a time. TCP utilizes the urgent mode (described in the TCP headers) as its means to identify and transport out-of-band data between sockets.

Reading or writing out-of-band data looks relatively simple and painless, but how does an application know when out-of-band data is available to read? One way to know is the sockatmark function, which tells the application that the next data to read is out-of-band data. Consider the example in Listing 6.1.

Listing 6.1 Receiving out-of-band data using sockatmark.

start example
int sock, ret, on; char buffer[100], oobdata; ... on = 1; ret = setsockopt( sock, SOL_SOCKET, SO_OOBINLINE,                     &on, sizeof(on) ); ... if (sockatmark( sock )) {   /* We're at the OOB byte position */   ret = read( sock, &oobdata, 1 );   } else {   /* Normal data coming... */   ret = read( sock, buffer, sizeof(buffer) ); }
end example

The sockatmark function simply tells the application that the next byte to be read is out-of-band data. Therefore, if sockatmark returns 1, we know that out-of-band data follows and we read it accordingly (in this case, using the read function). Otherwise, we read as we typically would, expecting a number of bytes. Note, in this case, that we’ve specified that out-of-band data will be received in line with our regular data (using the SOL_SOCKET option, SO_OOBINLINE). When normal in-band data is read, the read automatically stops at the out-of-band data. Therefore, a normal read reads only up to the point of the out-of-band data, and no further.

Unix systems may also use the SIGURG signal to identify when out-of-band data is available to be read. This method is covered within [Stevens98].



 < Day Day Up > 



BSD Sockets Programming from a Multi-Language Perspective
Network Programming for Microsoft Windows , Second Edition (Microsoft Programming Series)
ISBN: 1584502681
EAN: 2147483647
Year: 2003
Pages: 225
Authors: Jim Ohlund

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net