.TH recv() "" "" "Sockets Function (libsocket)"
.PC "Receive a message from a connected socket"
.B "#include <sys/types.h>"
.B "#include <sys/socket.h>"
\fBint recv(\fIsocket\^\fB, \fIbuffer\^\fB, \fIlength\^\fB, \fIflags\^\fB)\fR
\fBint \fIsocket\^\fB;\fR
\fBchar *\fIbuffer\^\fB;\fR
\fBint \fIlength\^\fB, \fIflags\^\fB;\fR
.PP
The function
.B recv()
receives messages from a connected socket.
.PP
.I socket
is the socket from which the messages are received.
It must have been created by the function
.BR socket() ,
and connected with the function
.BR connect() .
.I buffer
points to the chunk of memory into which the message is to be written;
.I length
gives the amount of allocated memory to which
.I buffer
points.
.PP
.I flags
ORs together either or both of the following flags:
.IP \fBMSG_OOB\fR
Read any out-of-band data present on
.IR socket ,
rather than the regular, in-band data.
.IP \fBMSG_PEEK\fR
``Peek'' at the data present on the socket:
the data are copied but not erased from the socket, so another call to
.B recv()
or
.BR recvfrom()
retrieves the same data.
.PP
If all goes well,
.B recv()
returns the number of bytes it read from
.IR socket .
If something went wrong, it returns \-1 and sets
.B errno
to one of the following values:
.IP \fBEAGAIN\fR
If no message is queued at
.IR socket ,
.B recv()
normally waits for a message to arrive (which is a blocking operation).
.IR socket ,
however, is marked as non-blocking.
.IP \fBEBADF\fR
.I socket
does not identify a valid socket.
.IP \fBEINTR\fR
A signal interrupted
.B recv()
before it could receive any data.
.IP \fBENOMEM\fR
Insufficient user memory was available to complete the operation.
.\" .IP \fBENOSR\fR
.\" Insufficient \*(ST resouces were available to complete the operation.
.IP \fBENOTSOCK\fR
.I socket
describes a file, not a socket.
.SH "See Also"
.Xr "connect()," connect
.Xr "libsocket," libsocket
.Xr "recvfrom()," recvfrom
.Xr "send()," send
.Xr "socket()" socket
