DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Programming with sockets

Data transfer

With a connection established, data may begin to flow. There are several calls for sending and receiving data. With the peer entity at each end of a connection anchored, a user can send or receive a message without specifying the peer. Here, the normal read and write system calls are usable:

   write(s, buf, sizeof(buf));
   read(s, buf, sizeof(buf));
In addition to read and write, the calls send and recv may be used:
   send(s, buf, sizeof(buf), flags);
   recv(s, buf, sizeof(buf), flags);
While send and recv are virtually identical to read and write, the extra flags argument is important. The flags, defined in sys/socket.h, may be specified as a non-zero value if one or more of the following is required:

MSG_NOSIGNAL don't send SIGPIPE when connection breaks
MSG_OOB send/receive out-of-band data
MSG_PEEK look at data without reading
MSG_DONTROUTE send data without routing packets
MSG_DONTWAIT enables non-blocking operation

Out-of-band data is specific to stream sockets. The option to have data sent without routing applied to the outgoing packets is currently used only by the routing table management process and is unlikely to be of interest to most users. However, the ability to preview data is of interest. When MSG_PEEK is specified with a recv call, any data present is returned to the user but treated as still unread. That is, the next read or recv call applied to the socket will return the data previously previewed.


© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005