File:  [Power 6/32 Unix Tahoe 4.2BSD] / cci / usr / src / man / man2 / recv.2
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Sun Jul 28 12:26:35 2019 UTC (7 years ago) by root
Branches: bsd, MAIN
CVS tags: v121, HEAD
Power 6/32 Unix version 1.21

.TH RECV 2 "7 July 1983"
.UC 4
.SH NAME
recv, recvfrom, recvmsg \- receive a message from a socket
.SH SYNOPSIS
.nf
.ft B
#include <sys/types.h>
#include <sys/socket.h>
.PP
.ft B
cc = recv(s, buf, len, flags)
int cc, s;
char *buf;
int len, flags;
.PP
.ft B
cc = recvfrom(s, buf, len, flags, from, fromlen)
int cc, s;
char *buf;
int len, flags;
struct sockaddr *from;
int *fromlen;
.PP
.ft B
cc = recvmsg(s, msg, flags)
int cc, s;
struct msghdr msg[];
int flags;
.ft R
.SH DESCRIPTION
.IR Recv ,
.IR recvfrom ,
and
.IR recvmsg
are used to receive messages from a socket.
.PP
The 
.I recv
call may be used only on a 
.I connected
socket (see
.IR connect (2)),
while 
.I recvfrom
and 
.I recvmsg
may be used to receive data on a socket whether
it is in a connected state or not.
.PP
If
.I from
is non-zero, the source address of the message is filled in.
.I Fromlen
is a value-result parameter, initialized to the size of
the buffer associated with
.IR from ,
and modified on return to indicate the actual size of the
address stored there.
The length of the message is returned in
.IR cc .
If a message is too long to fit in the supplied buffer,
excess bytes may be discarded depending on the type of socket
the message is received from; see
.IR socket (2).
.PP
If no messages are available at the socket, the
receive call waits for a message to arrive, unless
the socket is nonblocking (see
.IR ioctl (2))
in which case a
.I cc
of \-1 is returned with the external variable errno
set to EWOULDBLOCK.
.PP
The
.IR select (2)
call may be used to determine when more data arrives.
.PP
The
.I flags
argument to a receive call is formed by 
.IR or 'ing
one or more of the values,
.PP
.nf
.RS
.DT
#define	MSG_PEEK	0x1	/* peek at incoming message */
#define	MSG_OOB	0x2	/* process out-of-band data */
.RE
.fi
.PP
The
.I recvmsg
call uses a 
.I msghdr
structure to minimize the number of directly supplied parameters,
and to receive file descriptors from another process (Unix domain only).
This structure has the following form, as defined in
.IR <sys/socket.h> :
.PP
.nf
.RS
.DT
struct msghdr {
	caddr_t	msg_name;		/* optional address */
	int	msg_namelen;		/* size of address */
	struct	iov *msg_iov;		/* scatter/gather array */
	int	msg_iovlen;		/* # elements in msg_iov */
	caddr_t	msg_accrights;		/* access rights sent/received */
	int	msg_accrightslen;
};
.RE
.fi
.PP
Here
.I msg_name
and
.I msg_namelen
specify the destination address if the socket is unconnected;
.I msg_name
may be given as a null pointer if no names are desired or required.
The 
.I msg_iov
and
.I msg_iovlen
describe the scatter gather locations, as described in
.IR read (2).
Access rights to be sent along with the message are specified
in 
.IR msg_accrights ,
which has length
.IR msg_accrightslen .
.LP
.I RECEIVING OUT-OF-BAND DATA IN INTERNET DOMAIN
.LP
When out-of-band data arrives at a socket, the system could signal
a group of processes, or a specific process, or no process at all.
.RS

- If the socket's process group id is 
.I positive,
the system signals all  process in that process group.

- If the socket's process group id is
.I negative,
the system only signals the process whose process id is the absolute
value of the socket's process group id.

- If the socket's process group id is 0 (the default value), 
the system does not signal any process.

.RE
To assign a socket process group id, use the 
.I ioctl(2)
system call with the command
.I SIOCSPGRP.
.LP
.I RECEIVING FILE DESCRIPTORS IN UNIX DOMAIN
.LP
In Unix domain, process
.I A
can open a set of files, then send these file descriptors to process
.I B.
Process
.I B
then can read or write those files which were already opened (and
perhaps accessible only) by 
.I A.
.LP
The active process stores the file descriptors
in the field
.I  msg_accrights
of the structure
.I msghdr,
and use the system call
.I sendmsg(2)
to send the descriptors. The passive process then can receive the
descriptors via the system call
.I recvmsg(2);
the descriptors are returned in the field
.I msg_accrights
of
.I msghdr.
.SH "RETURN VALUE
These calls return the number of bytes received, or \-1
if an error occurred.
.SH ERRORS
The calls fail if:
.TP 20
[EBADF]
The argument \fIs\fP is an invalid descriptor.
.TP 20
[ENOTSOCK]
The argument \fIs\fP is not a socket.
.TP 20
[EWOULDBLOCK]
The socket is marked non-blocking and the receive operation
would block.
.TP 20
[EINTR]
The receive was interrupted by delivery of a signal before
any data was available for the receive.
.TP 20
[EFAULT]
The data was specified to be received into a non-existent
or protected part of the process address space.
.SH SEE ALSO
read(2), send(2), socket(2). See also bind(2) for address formats 
in different communication domains.

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.