1RECV(3P)                   POSIX Programmer's Manual                  RECV(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       recv - receive a message from a connected socket
13

SYNOPSIS

15       #include <sys/socket.h>
16
17       ssize_t recv(int socket, void *buffer, size_t length, int flags);
18
19

DESCRIPTION

21       The recv() function shall receive a message from a  connection-mode  or
22       connectionless-mode  socket. It is normally used with connected sockets
23       because it does not permit  the  application  to  retrieve  the  source
24       address of received data.
25
26       The recv() function takes the following arguments:
27
28       socket Specifies the socket file descriptor.
29
30       buffer Points to a buffer where the message should be stored.
31
32       length Specifies  the  length  in bytes of the buffer pointed to by the
33              buffer argument.
34
35       flags  Specifies the type of message reception. Values of this argument
36              are  formed  by  logically  OR'ing zero or more of the following
37              values:
38
39       MSG_PEEK
40              Peeks at an incoming message. The data is treated as unread  and
41              the  next  recv()  or  similar  function shall still return this
42              data.
43
44       MSG_OOB
45              Requests out-of-band data. The  significance  and  semantics  of
46              out-of-band data are protocol-specific.
47
48       MSG_WAITALL
49              On  SOCK_STREAM  sockets  this  requests that the function block
50              until the full amount of data can be returned. The function  may
51              return  the  smaller  amount of data if the socket is a message-
52              based socket, if a signal is caught, if the connection is termi‐
53              nated,  if MSG_PEEK was specified, or if an error is pending for
54              the socket.
55
56
57
58       The recv() function shall return the length of the message  written  to
59       the  buffer  pointed to by the buffer argument. For message-based sock‐
60       ets, such as SOCK_DGRAM and SOCK_SEQPACKET, the entire message shall be
61       read  in  a  single  operation.  If a message is too long to fit in the
62       supplied buffer, and MSG_PEEK is not set in  the  flags  argument,  the
63       excess  bytes  shall  be  discarded.  For stream-based sockets, such as
64       SOCK_STREAM, message boundaries shall be ignored. In  this  case,  data
65       shall  be  returned to the user as soon as it becomes available, and no
66       data shall be discarded.
67
68       If the MSG_WAITALL flag is not set, data shall be returned only  up  to
69       the end of the first message.
70
71       If no messages are available at the socket and O_NONBLOCK is not set on
72       the socket's file  descriptor,  recv()  shall  block  until  a  message
73       arrives.  If  no messages are available at the socket and O_NONBLOCK is
74       set on the socket's file descriptor, recv() shall fail and set errno to
75       [EAGAIN] or [EWOULDBLOCK].
76

RETURN VALUE

78       Upon  successful completion, recv() shall return the length of the mes‐
79       sage in bytes. If no messages are available to be received and the peer
80       has performed an orderly shutdown, recv() shall return 0. Otherwise, -1
81       shall be returned and errno set to indicate the error.
82

ERRORS

84       The recv() function shall fail if:
85
86       EAGAIN or EWOULDBLOCK
87
88              The socket's file descriptor is marked O_NONBLOCK and no data is
89              waiting  to  be  received;  or MSG_OOB is set and no out-of-band
90              data is available and either the  socket's  file  descriptor  is
91              marked  O_NONBLOCK  or  the  socket does not support blocking to
92              await out-of-band data.
93
94       EBADF  The socket argument is not a valid file descriptor.
95
96       ECONNRESET
97              A connection was forcibly closed by a peer.
98
99       EINTR  The recv() function was interrupted by a signal that was caught,
100              before any data was available.
101
102       EINVAL The MSG_OOB flag is set and no out-of-band data is available.
103
104       ENOTCONN
105              A  receive  is attempted on a connection-mode socket that is not
106              connected.
107
108       ENOTSOCK
109              The socket argument does not refer to a socket.
110
111       EOPNOTSUPP
112              The specified flags are not supported for this  socket  type  or
113              protocol.
114
115       ETIMEDOUT
116              The connection timed out during connection establishment, or due
117              to a transmission timeout on active connection.
118
119
120       The recv() function may fail if:
121
122       EIO    An I/O error occurred while reading from or writing to the  file
123              system.
124
125       ENOBUFS
126              Insufficient  resources  were available in the system to perform
127              the operation.
128
129       ENOMEM Insufficient memory was available to fulfill the request.
130
131
132       The following sections are informative.
133

EXAMPLES

135       None.
136

APPLICATION USAGE

138       The recv() function is equivalent to recvfrom() with a zero address_len
139       argument, and to read() if no flags are used.
140
141       The select() and poll() functions can be used to determine when data is
142       available to be received.
143

RATIONALE

145       None.
146

FUTURE DIRECTIONS

148       None.
149

SEE ALSO

151       poll(), read(), recvmsg(),  recvfrom(),  select(),  send(),  sendmsg(),
152       sendto(), shutdown(), socket(), write(), the Base Definitions volume of
153       IEEE Std 1003.1-2001, <sys/socket.h>
154
156       Portions of this text are reprinted and reproduced in  electronic  form
157       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
158       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
159       Specifications  Issue  6,  Copyright  (C) 2001-2003 by the Institute of
160       Electrical and Electronics Engineers, Inc and The Open  Group.  In  the
161       event of any discrepancy between this version and the original IEEE and
162       The Open Group Standard, the original IEEE and The Open Group  Standard
163       is  the  referee document. The original Standard can be obtained online
164       at http://www.opengroup.org/unix/online.html .
165
166
167
168IEEE/The Open Group                  2003                             RECV(3P)
Impressum