HP OpenVMS Systems Documentation |
HP TCP/IP Services for OpenVMS
|
Previous | Contents | Index |
Receives bytes from a connected socket and places them into a user-provided buffer.The $QIO equivalent is the IO$_READVBLK function.
#include <types.h>#include <socket.h>
int recv ( int s, char *buf, int len, int flags );
(_DECC_V4_SOURCE)
size_t recv ( int s, void *buf, ssize_t len, int flags );(not_DECC_V4_SOURCE)
s
A socket descriptor created as the result of a call to accept() or connect() .buf
A pointer to a user-provided buffer into which received data will be placed.len
The size of the buffer pointed to by buf.flags
A bit mask that can contain one or more of the following flags. The mask is built by using a logical OR operation on the appropriate values.
Flag Description MSG_OOB Allows you to receive out-of-band data. If out-of-band data is available, it is read first. If no out-of-band data is available, the MSG_OOB flag is ignored. Use the send() , sendmsg() , and sendto() functions to send out-of-band data. MSG_PEEK Allows you to examine data in the receive buffer without removing it from the system's buffers.
This function receives data from a connected socket. To receive data on an unconnected socket, use the recvfrom() or recvmsg() functions. The received data is placed in the buffer buf.Data is sent by the socket's peer using the send , sendmsg() , sendto() , or write() functions.
Use the select() function to determine when more data arrives.
If no data is available at the socket, the recv() call waits for data to arrive, unless the socket is nonblocking. If the socket is nonblocking, a -1 is returned with the external variable errno set to EWOULDBLOCK .
Related Functions
See also read() , send() , sendmsg() , sendto() , and socket() .
x The number of bytes received and placed in buf. 0 Peer has closed its send side of the connection. -1 Error; errno is set to indicate the error.
EBADF The socket descriptor is invalid. ECONNRESET A connection was forcibly closed by a peer. EFAULT The data was specified to be received into a nonexistent or protected part of the process address space. EINTR A signal interrupted the recv() function before any data was available. EINVAL The MSG_OOB flag is set and no out-of-band data is available. ENOBUFS The system has insufficient resources to complete the call. ENOMEM The system did not have sufficient memory to fulfill the request. ENOTCONN A receive is attempted on a connection-oriented socket that is not connected. ENOTSOCK The socket descriptor is invalid. EOPNOTSUPP The specified flags are not supported for this socket type or protocol. EWOULDBLOCK The socket is marked nonblocking, and no data is waiting to be received.
Receives bytes for a socket from any source.
#include <types.h>#include <socket.h>
int recvfrom ( int s, char *buf, int len, int flags, struct sockaddr *from, int *fromlen)
; (_DECC_V4_SOURCE)
ssize_t recvfrom ( int s, void *buf, size_t len, int flags, struct sockaddr *from, size_t *fromlen); (not_DECC_V4_SOURCE)
s
A socket descriptor created with the socket() function and bound to a name using the bind() function or as a result of the accept() function.buf
A pointer to a buffer into which received data is placed.len
The size of the buffer pointed to by buf.flags
A bit mask that can contain one or more of the following flags. The mask is built by using a logical OR operation on the appropriate values.
Flag Description MSG_OOB Allows you to receive out-of-band data. If out-of-band data is available, it is read first. If no out-of-band data is available, the MSG_OOB flag is ignored. To send out-of-band data, use the send() , sendmsg() , and sendto() functions.
MSG_PEEK Allows you to examine the data that is next in line to be received without actually removing it from the system's buffers. from
A buffer that the recvfrom() function uses to place the address of the sender who sent the data.If from is non-null, the address is returned. If from is null, the address is not returned.
fromlen
Points to an integer containing the size of the buffer pointed to by from. On return, the integer is modified to contain the actual length of the socket address structure returned.
This function allows a named, unconnected socket to receive data. The data is placed in the buffer pointed to by buf, and the address of the sender of the data is placed in the buffer pointed to by from if from is non-null. The structure that from points to is assumed to be as large as the sockaddr structure. See Section 3.2.12 for a description of the sockaddr structure.To receive bytes from any source, the socket does not need to be connected.
You can use the select() function to determine if data is available.
If no data is available at the socket, the recvfrom() call waits for data to arrive, unless the socket is nonblocking. If the socket is nonblocking, a -1 is returned with the external variable errno set to EWOULDBLOCK .
Related Functions
See also read() , send() , sendmsg() , sendto() , and socket() .
x The number of bytes of data received and placed in buf. 0 Successful completion. -1 Error; errno is set to indicate the error.
EBADF The socket descriptor is invalid. ECONNRESET A connection was forcibly closed by a peer. EFAULT A valid message buffer was not specified. Nonexistent or protected address space is specified for the message buffer. EINTR A signal interrupted the recvfrom() function before any data was available. EINVAL The MSG_OOB flag is set, and no out-of-band data is available. ENOBUFS The system has insufficient resources to complete the call. ENOMEM The system did not have sufficient memory to fulfill the request. ENOTCONN A receive is attempted on a connection-oriented socket that is not connected. ENOTSOCK The socket descriptor is invalid. EOPNOTSUPP The specified flags are not supported for this socket type. ETIMEDOUT The connection timed out when trying to establish a connection or when a transmission timed out on an active connection. EWOULDBLOCK The NBIO (nonblocking) flag is set for the socket descriptor and the process delayed during the write operation.
Receives bytes on a socket and places them into scattered buffers.
#include <types.h>#include <socket.h>
int recvmsg ( int s, struct msghdr msg, int flags ); (BSD Version 4.4)
int recvmsg ( int s, struct omsghdr msg, int flags ); (BSD Version 4.3)
s
A socket descriptor created with the socket() function.msg
A pointer to a msghdr structure for receiving the data. See Section 3.2.8 for a description of the msghdr structure.flags
A bit mask that can contain one or more of the following flags. The mask is built by using a logical OR operation on the appropriate values.
Flag Description MSG_OOB Allows you to receive out-of-band data. If out-of-band data is available, it is read first. If no out-of-band data is available, the MSG_OOB flag is ignored. Use send() , sendmsg() , and sendto() functions to send out-of-band data. MSG_PEEK Allows you to peek at the data that is next in line to be received without actually removing it from the system's buffers.
You can use this function with any socket, whether or not it is in a connected state. It receives data sent by a call to sendmsg() , send() , or sendto() . The message is scattered into several user buffers if such buffers are specified.To receive data, the socket does not need to be connected to another socket.
When the ioveciovcnt array specifies more than one buffer, the input data is scattered into iovcnt buffers as specified by the members of the iovec array:
iov0, iov1, ..., ioviovcntWhen a message is received, it is split among the buffers by filling the first buffer in the list, then the second, and so on, until either all of the buffers are full or there is no more data to be placed in the buffers.
You can use the select() function to determine when more data arrives.
Related Functions
See also read() , send() , and socket() .
x The number of bytes returned in the msg_iov buffers. 0 Successful completion. -1 Error; errno is set to indicate the error.
EBADF The socket descriptor is invalid. ECONNRESET A connection was forcibly closed by a peer. EFAULT The message argument is not in a readable or writable part of user address space. EINTR This function was interrupted by a signal before any data was available. EINVAL The MSG_OOB flag is set, and no out-of-band data is available. The value of the msg_iovlen member of the msghdr structure is less than or equal to zero or is greater than IOV_MAX .
ENOBUFS The system has insufficient resources to complete the call. ENOMEM The system did not have sufficient memory to fulfill the request. ENOTCONN A receive is attempted on a connection-oriented socket that is not connected. ENOTSOCK The socket descriptor is invalid. EOPNOTSUPP The specified flags are not supported for this socket type. EWOULDBLOCK The socket is marked nonblocking, and no data is ready to be received.
Allows you to poll or check a group of sockets for I/O activity. This function indicates which sockets are ready to be read or written, or which sockets have an exception pending.
#include <time.h>int select ( int nfds, int *readfds, int *writefds, int *execptfds, struct timeval *timeout );
(_DECC_V4_SOURCE)
int select ( int nfds, fd_set *readfds, fd_set *writefds, int *execptfds, struct timeval *timeout );(not_DECC_V4_SOURCE)
nfds
The number of open objects that may be ready for reading or writing or that have exceptions pending. The nfds argument is normally limited to FD_SETSIZE , which is defined in the SOCKET.H header file. Note that a single process can have a maximum of 65535 simultaneous channels (including sockets) on OpenVMS Alpha and I64 systems, and a maximum of 2047 on OpenVMS VAX systems.readfds
A pointer to an array of bits, organized as integers, that should be examined for read readiness. If bit n of the longword is set, socket descriptor n is checked to see whether it is ready to be read. All bits set in the bit mask must correspond to the file descriptors of sockets. The select() function cannot be used on normal files.On return, the array to which readfds points contains a bit mask of the sockets that are ready for reading. Only bits that were set on entry to the select() function can be set on exit.
writefds
A pointer to an array of bits, organized as integers, that should be examined for write readiness. If bit n of the longword is set, socket descriptor n is checked to see whether it is ready to be written to. All bits set in the bit mask must correspond to socket descriptors.On return, the array to which writefds points contains a bit mask of the sockets that are ready for writing. Only bits that were set on entry to the select() function are set on exit.
exceptfds
A pointer to an array of bits, organized as integers, that is examined for exceptions. If bit n of the longword is set, socket descriptor n is checked to see whether it has any pending exceptions. All bits set in the bit mask must correspond to the file descriptors of sockets.On return, the array exceptfds pointer contains a bit mask of the sockets that have exceptions pending. Only bits that were set on entry to the select() function can be set on exit.
timeout
The length of time that the select() function should examine the sockets before returning. If one of the sockets specified in the readfds, writefds, and exceptfds bit masks is ready for I/O, the select() function returns before the timeout period expires.The timeout argument points to a timeval structure. See Section 3.2.15 for a description of the timeval structure.
This function determines the I/O status of the sockets specified in the various mask arguments. It returns when a socket is ready to be read or written, when the timeout period expires, or when exceptions occur. If timeout is a non-null pointer, it specifies a maximum interval to wait for the selection to complete.If the timeout argument is null, the select() function blocks indefinitely until a selected event occurs. To effect a poll, the value for timeout should be non-null, and should point to a zero-value structure.
If a process is blocked on a select() function while waiting for input for a socket and the sending process closes the socket, then the select() function notes this as an event and unblocks the process. The descriptors are always modified on return if the select() function returns because of the timeout.
Note
When the socket option SO_OOBINLINE is set on the device socket, the select() function on both read and exception events returns the socket mask that is set on both the read and the exception mask. Otherwise, only the exception mask is set.Related Functions
See also accept() , connect() , read() , recv() , recvfrom() , recvmsg() , send() , sendmsg() , sendto() , and write() .
n The number of sockets ready for I/O or pending exceptions. This value matches the number of returned bits that are set in all output masks. 0 The select() function timed out before any socket became ready for I/O. -1 Error; errno is set to indicate the error.
EBADF One or more of the I/O descriptor sets specified an invalid file descriptor. EINTR A signal was delivered before the time limit specified by the timeout argument expired and before any of the selected events occurred. EINVAL The time limit specified by the timeout argument is invalid. The nfds argument is less than zero, or greater than or equal to FD_SETSIZE .
EAGAIN Allocation of internal data structures failed. A later call to the select() function may complete successfully. ENETDOWN TCP/IP Services was not started. ENOTSOCK The socket descriptor is invalid.
Previous | Next | Contents | Index |