Data Transfer
This section describes the interfaces to send and receive data. You can send or
receive a message with the read
()
and write
()
interfaces as follows:
write(s, buf, sizeof buf); read(s, buf, sizeof buf);
You can also use send
()
and recv
().
send(s, buf, sizeof buf, flags); recv(s, buf, sizeof buf, flags);
send
()
and recv
()
are
similar to read
()
and write
(), but the
flags
argument is required. The
flags
argument, which is defined in
sys/socket.h
, can be specified as a nonzero value if
one or more of the following is required:
-
MSG_OOB
-
Send and receive out-of-band data
-
MSG_PEEK
-
Look at data without reading
-
MSG_DONTROUTE
-
Send data without routing packets
Out-of-band data is specific to stream sockets. When
MSG_PEEK
is specified with a recv
()
call, any data present is returned to the user, but treated as still
unread. The next read
()
or recv
()
call
on the socket returns the same data. The option to send data without
routing packets applied to the outgoing packets is currently used only
by the routing table management process.
For more information, see the
read
(2),
write
(2),
send
(3C), and
recv
(3C) man pages.