|
HP OpenVMS systems documentation |
Previous | Contents | Index |
Sends bytes through a socket to its connected peer.The $QIO equivalent is the IO$_WRITEVBLK function.
#include <types.h>#include <socket.h>
int send ( int s, char *msg, int len, int flags );
(_DECC_V4_SOURCE)
ssize_t send ( int s, const void *msg, size_t len, int flags );(not_DECC_V4_SOURCE)
s
A socket descriptor created with the socket() function that was connected to another socket using the accept() or connect() function.msg
A pointer to a buffer containing the data to be sent.len
The length, in bytes, of the data pointed to by msg.flags
Can be either 0 or MSG_OOB. If it is MSG_OOB, the data is sent out of band. Data can be received before other pending data on the receiving socket if the receiver also specifies MSG_OOB in the flag argument of its recv() or recvfrom() call.
This function sends data to a connected peer.You can use this function only on connected sockets. To send data on an unconnected socket, use the sendmsg() or sendto() function. The send() function passes data along to its connected peer, which can receive the data by using the recv() or read() function.
Normally the send() function blocks if there is no space for the incoming data in the buffer. It waits until the buffer space becomes available. If the socket is set to nonblocking and there is no space for the data, the send() function fails with the EWOULDBLOCK error.
If the message is too large to be sent in one piece, and the socket type is SOCK_DGRAM , which requires that messages be sent in one piece, send() fails with the EMSGSIZE error.
If the address specified is an INADDR_BROADCAST address, then the SO_BROADCAST socket option must have been set and the process must have SYSPRV or BYPASS privilege for the I/O operation to succeed.
A success return from the send() does not guarantee that the data has been received by the peer. All errors (except EWOULDBLOCK ) are detected locally. To determine when it is possible to send more data, use the select() function.
Related Functions
See also read() , recv() , recvmsg() , recvfrom() , getsockopt() , and socket() .
n The number of bytes sent. This value normally equals len. -1 Error; errno is set to indicate the error.
EBADF The socket descriptor is invalid. ECONNRESET A connection was forcibly closed by a peer. EDESTADDRREQ The socket is not connection-oriented, and no peer address is set. EFAULT The message argument is not in a readable or writable part of the user address space. EINTR A signal interrupted the send() before any data was transmitted. EMSGSIZE The message is too large to be sent all at once, as the socket requires. ENETDOWN The local network connection is not operational. ENETUNREACH The destination network is unreachable. ENOBUFS The system has insufficient resources to complete the call. ENOTCONN The socket is not connected or has not had the peer prespecified. ENOTSOCK The socket descriptor is invalid. EOPNOTSUPP The socket argument is associated with a socket that does not support one or more of the values set in flags. EWOULDBLOCK The socket is marked nonblocking, and no space is available for the send() function.
Sends gathered bytes through a socket to any other socket.
#include <types.h>#include <socket.h>
int sendmsg ( int s, struct msghdr *msg, int flags ); (BSD Version 4.4)
int sendmsg ( 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 containing the message to be sent. See Section 3.2.8 for a description of the msghdr structure.The msg_iov field of the msghdr structure is used as a series of buffers from which data is read in order until msg_iovlen bytes have been obtained.
flags
Can be either 0 or MSG_OOB . If it is equal to MSG_OOB , the data is sent out of band. Data can be received before other pending data on the receiving socket if the receiver specifies a flag of MSG_OOB .
This function sends the data in a msghdr structure to any other socket.You can use this function on any socket to send data to any named socket. The data in the msg_iov field of the msghdr structure is sent to the socket whose address is specified in the msg_name field of the structure. The receiving socket gets the data using the read() , recv() , recvfrom() , or recvmsg() function. When the iovec array specifies more than one buffer, the data is gathered from all specified buffers before being sent. See Section 3.2.6 for a description of the iovec structure.
Normally the sendmsg() function blocks if there is no space for the incoming data in the buffer. It waits until the buffer space becomes available. If the socket is set to nonblocking and there is no space for the data, the sendmsg() function fails with the EWOULDBLOCK error.
If the message is too large to be sent in one piece, and the socket type is SOCK_DGRAM , which requires that messages be sent in one piece, sendmsg() fails with the EMSGSIZE error.
If the address specified is an INADDR_BROADCAST address, the SO_BROADCAST socket option must be set and the process must have OPER, SYSPRV, or BYPASS privilege for the I/O operation to succeed.
A success return from sendmsg() does not guarantee that the data has been received by the peer. All errors (except EWOULDBLOCK ) are detected locally. To determine when it is possible to send more data, use the select() function.
Related Functions
See also read() , recv() , recvfrom() , recvmsg() , socket() , and getsockopt() .
n The number of bytes sent. -1 Error; errno is set to indicate the error.
ENOTSOCK The socket descriptor is invalid. EFAULT An invalid user space address is specified for an argument. EMSGSIZE The socket requires that messages be sent atomically, but the size of the message to be sent makes this impossible. EWOULDBLOCK Blocks if the system does not have enough space for buffering the user data.
Sends bytes through a socket to any other socket.The $QIO equivalent is the IO$_WRITEVBLK function.
#include <types.h>#include <socket.h>
int sendto ( int s, char *msg, int len, int flags, struct sockaddr *to, int tolen );
(_DECC_V4_SOURCE)
ssize_t sendto ( int s, const void *msg, size_t len, int flags, const struct sockaddr *to, size_t tolen );(not_DECC_V4_SOURCE)
s
A socket descriptor created with the socket() function.msg
A pointer to a buffer containing the data to be sent.len
The length of the data pointed to by the msg argument.flags
Can be either 0 or MSG_OOB . If it is MSG_OOB , the data is sent out of band. Data can be received before other pending data on the receiving socket if the receiver specifies MSG_OOB in the flag argument of its recv() , recvfrom() or recvmsg() call.to
Points to the address structure of the socket to which the data is to be sent.tolen
The length of the address pointed to by the to argument.
This function can be used on sockets to send data to named sockets. The data in the msg buffer is sent to the socket whose address is specified in the to argument, and the address of socket s is provided to the receiving socket. The receiving socket gets the data using the read() , recv() , recvfrom() , or recvmsg() function.Normally the sendto() function blocks if there is no space for the incoming data in the buffer. It waits until the buffer space becomes available. If the socket is set to nonblocking and there is no space for the data, the sendto() function fails with the EWOULDBLOCK error.
If the message is too large to be sent in one piece, and the socket type is SOCK_DGRAM , which requires that messages be sent in one piece, sendto() fails with the EMSGSIZE error.
If the address specified is a INADDR_BROADCAST address, then the SO_BROADCAST socket option must have been set and the process must have SYSPRV or BYPASS privilege for the I/O operation to succeed.
A success return from the sendto() does not guarantee that the data has been received by the peer. All errors (except EWOULDBLOCK ) are detected locally. To determine when it is possible to send more data, use the select() function.
Related Functions
See also read() , recv() , recvfrom() , recvmsg() , socket() , and getsockopt() .
n The number of bytes sent. This value normally equals len. -1 Error; errno is set to indicate the error.
EAFNOSUPPORT Addresses in the specified address family cannot be used with this socket. EBADF The socket descriptor is invalid. ECONNRESET A connection was forcibly closed by a peer. EDESTADDRREQ You did not specify a destination address for the connectionless socket and no peer address is set. EFAULT An invalid user space address is specified for an argument. EHOSTUNREACH The destination host is unreachable. EINTR A signal interrupted sendto() before any data was transmitted. EINVAL The tolen argument is not a valid size for the specified address family. EISCONN The connection-oriented socket for which a destination address was specified is already connected. EMSGSIZE The message is too large to be sent all at once, as the socket requires. ENETDOWN The local network connection is not operational. ENETUNREACH The destination network is unreachable. ENOBUFS The system has insufficient resources to complete the call. ENOMEM The system did not have sufficient memory to fulfill the request. ENOTCONN The socket is connection-oriented but is not connected. ENOTSOCK The socket descriptor is invalid. EOPNOTSUPP The socket argument is associated with a socket that does not support one or more of the values set in flags. EPIPE The socket is shut down for writing or is connection oriented, and the peer is closed or shut down for reading. In the latter case, if the socket is of type SOCK_STREAM , the SIGPIPE signal is generated to the calling process. EWOULDBLOCK The socket is marked nonblocking, and no space is available for the sendto() function.
Opens the hosts database file.
#include <netdb.h>void sethostent (int stay_open);
stay_open
Specifies a value used to indicate when to close the hosts database file (TCPIP$ETC:IPNODES.DAT):
- A value of 0 closes the hosts database file after each call to the gethostbyname() , gethostbyaddr() , or gethostent() function.
- A nonzero value keeps the hosts database file open after each call.
This function opens the hosts database file and resets the file marker to the beginning of the file.Passing a nonzero value to the stay_open argument keeps the connection open until the endhostent() or exit() function is called.
Related Functions
See also endhostent() .
Opens the networks database file.
#include <netdb.h>void setnetent (int stay_open);
stay_open
Specifies a value used to indicate when to close the networks database file (TCPIP$SYSTEM:NETWORKS.DAT):
- A value of 0 closes the networks database file after each call to the getnetent() function.
- A nonzero value keeps the networks database file open after each call.
This function opens the networks database file and resets the file marker to the beginning of the file.Passing a nonzero stay_open argument keeps the connection open until you call the endnetent() or exit() function.
Related Functions
See also endnetent() , getnetent() , and exit() .
Sets the state of the protocols table.
#include <netdb.h>void setprotoent (int stay_open);
stay_open
Specifies a value used to indicate when to reset the protocols table index:
- A value of 0 resets the protocols table index after each call to the getprotoent function.
- A nonzero value does not reset the protocols table index after each call.
This function sets the index marker to the beginning of the protocols table.Passing a nonzero stay_open argument will allow the index to advance until you call the endprotoent() or exit() function.
Related Functions
See also endprotoent() , exit() , and getprotoent() .
1 Indicates success. 0 Indicates an error; unable to access the protocols table.
Opens the services database file.
#include <netdb.h>void setservent (int stay_open);
stay_open
Specifies a value used to indicate when to close the services database file (TCPIP$ETC:SERVICES.DAT):
- A value of 0 closes the services database file after each call to the setservent() function.
- A nonzero value keeps the services database file open after each call to setservent() .
This function opens the services database file and resets the file marker to the beginning of the file.Passing a nonzero stay_open argument keeps the connection open until you call the endservent() function or the exit() function.
Related Functions
See also endservent() , exit() , and getservent() .
Sets options on a socket.The $QIO equivalent is the IO$_SETMODE function.
#include <types.h>#include <socket.h>
int setsockopt ( int s, int level, int optname, char *optval, int optlen );
(_DECC_V4_SOURCE)
int setsockopt ( int s, int level, int optname, const void *optval, size_t optlen );(not_DECC_V4_SOURCE)
s
A socket descriptor created by the socket() function.level
The protocol level for which the socket options are to be modified. It can have one of the following values:
SOL_SOCKET Set the options at the socket level. p Any protocol number. Set the options for protocol level p. For IPv4, see the IN.H header file for the IPPROTO values. For IPv6, see the IN6.H header file for the IPPROTO_IPV6 values. optname
Interpreted by the protocol specified in level. Options at each protocol level are documented with the protocol.Refer to:
- Table A-1 for a list of socket options
- Table A-2 for a list of TCP options
- Table A-3 for a list of IP options
optval
Points to a buffer containing the arguments of the specified option.All socket-level options other than SO_LINGER should be nonzero if the option is to be enabled, or zero if it is to be disabled.
SO_LINGER uses a linger structure argument defined in the SOCKET.H header file. This structure specifies the desired state of the option and the linger interval. The option value for the SO_LINGER command is the address of a linger structure. See Section 3.2.7 for a description of the linger structure.
If the socket is type SOCK_STREAM , which promises the reliable delivery of data, and l_onoff is nonzero, the system blocks the process on the close() attempt until it is able to transmit the data or until it decides it is unable to deliver the information. A timeout period, called the linger interval, is specified in l_linger .
If l_onoff is set to zero and a close() is issued, the system processes the close in a manner that allows the process to continue as soon as possible.
optlen
An integer specifying the size of the buffer pointed to by optval.
This function manipulates options associated with a socket. Options can exist at multiple protocol levels. They are always present at the uppermost socket level.When manipulating socket options, specify the level at which the option resides and the name of the option. To manipulate options at the socket level, specify the value of level as SOL_SOCKET. To manipulate options at any other level, supply the protocol number of the appropriate protocol controlling the option. For example, to indicate that an option is to be interpreted by TCP, set the value for the level argument to the protocol number (IPPROTO_TCP) of TCP.
For IPv4, see the IN.H header file for the various IPPROTO values. For IPv6, see the IN6.H header file for the various IPPROTO_IPV6 values.
0 Successful completion. -1 Error; errno is set to indicate the error.
EACCES The calling process does not have appropriate permissions. EBADF The descriptor is invalid. EDOM The send and receive timeout values are too large to fit in the timeout fields of the socket structure. EINVAL The optlen argument is invalid. EISCONN The socket is already connected; the specified option cannot be set when the socket is in the connected state. EFAULT The optval argument is not in a readable part of the user address space. ENOBUFS The system had insufficient resources to complete the call. ENOPROTOOPT The option is unknown. ENOTSOCK The socket descriptor is invalid. EFAULT The optname argument is invalid.
Previous | Next | Contents | Index |