recv.2

来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· 2 代码 · 共 171 行

2
171
字号
.\" SCCSID: @(#)recv.2	8.1	9/11/90.TH recv 2.SH Namerecv, recvfrom, recvmsg \- receive a message from a socket.SH Syntax.nf.ft B#include <sys/types.h>#include <sys/socket.h>.PP.ft Bcc = recv(s, buf, len, flags)int cc, s;char *buf;int len, flags;.PP.ft Bcc = recvfrom(s, buf, len, flags, from, fromlen)int cc, s;char *buf;int len, flags;struct sockaddr *from;int *fromlen;.PP.ft Bcc = recvmsg(s, msg, flags)int cc, s;struct msghdr msg[];int flags;.ft R.SH Description.NXR "recv system call".NXR "recvfrom system call".NXR "recvmsg system call".NXA "recv system call" "send system call".NXR "socket" "receiving message from"The.PN recv ,.PN recvfrom ,and.PN recvmsgsystem calls are used to receive messages from a socket..PPThe .PN recvcall can be used only on a connected socket. The  .PN recvfromand .PN recvmsgcalls can be used to receive data on a socket, whether or notit is in a connected state.For further information, see .MS connect 2 ..PPIf.I fromis nonzero, the source address of the message is filled in.The.I fromlenis a value-result parameter, initialized to the size ofthe buffer associated with.IR from ,and modified on return to indicate the actual size of theaddress stored there.The length of the message is returned in.PN cc .If a message is too long to fit in the supplied buffer,excess bytes can be discarded, depending on the type of socketthe message is received from.  For further information, see.MS socket 2 ..PPIf no messages are available at the socket, thereceive call waits for a message to arrive, unlessthe socket is nonblocking.  If the socket is nonblocking,a.PN ccof \-1 is returned, and the external variable errno isset to EWOULDBLOCK.For further information, see .MS ioctl 2 ..PPThe .MS select 2call can be used to determine when more data arrives..PPThe.I flagsargument to a send call is formed by ORingone or more of the values following values:.EX 0#define	MSG_OOB	0x1	/* process out-of-band data */#define	MSG_PEEK	0x2	/* peek at incoming message */.EEThe.PN recvmsgcall uses a .I msghdrstructure to minimize the number of directly supplied parameters.This structure has the following form, as defined in <sys/socket.h>:.NXR(e) "recv system call" "msghdr structure".EX 0struct 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;};.EEHere,.I msg_nameand.I msg_namelenspecify the destination address if the socket is unconnected;.I msg_namecan be given as a null pointer if no names are desired or required.The .I msg_iovand.I msg_iovlendescribe the scatter gather locations, as described in.MS read 2 .Access rights to be sent along with the message are specifiedin .I msg_accrights ,which has length.I msg_accrightslen ..SH Return ValuesThese calls return the number of bytes received, or \-1if an error occurred..SH Diagnostics.NXR "recv system call" "diagnostics"The .PN recvcall fails under the following conditions:.TP 15[EBADF]The argument \fIs\fP is an invalid descriptor..TP 15[EINVAL]The argument length of the message is less than 0..TP 15[EMSGSIZE]The message sent on the socket was larger than theinternal message buffer..TP 15[ENOTCONN]A call was made to .PN recvfrom an unconnected stream socket..TP 15[ENOTSOCK]The argument \fIs\fP is not a socket..TP 15[EWOULDBLOCK]The socket is marked nonblocking and the receive operationwould block..TP 15[EINTR]The receive was interrupted by delivery of a signal beforeany data was available for the receive..TP 15[EFAULT]The data was specified to be received into a nonexistentor protected part of the process address space. The argument \fIfromlen\fPpoints outside the process address space..SH See Alsoread(2), send(2), socket(2)

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?