send()--Send Data
BSD 4.3 Syntax
#include <sys/types.h> #include <sys/socket.h> int send(int socket_descriptor, char *buffer, int buffer_length, int flags)
Service Program Name: QSOSRV1
Default Public Authority: *USE
Threadsafe: Yes
UNIX® 98 Compatible Syntax
#define _XOPEN_SOURCE 520 #include <sys/socket.h> ssize_t send(int socket_descriptor, const void *buffer, size_t buffer_length, int flags)
Service Program Name: QSOSRV1
Default Public Authority: *USE
Threadsafe: Yes
The send() function is used to send data through a connected socket.
There are two versions of the API, as shown above. The base IBM® i API uses BSD 4.3 structures and syntax. The other uses syntax and structures compatible with the UNIX 98 programming interface specifications. You can select the UNIX 98 compatible interface with the _XOPEN_SOURCE macro.
Parameters
- socket_descriptor
- (Input) The socket descriptor that is to be written to.
- buffer
- (Input) The pointer to the buffer in which the data that is to be written
is stored.
- buffer_length
- (Input) The length of the buffer.
- flags
- (Input) A flag value that controls the transmission of the data. The
flags value is either zero, or is obtained by performing an OR
operation on the following constants:
MSG_EOR Terminate a record, if supported by the protocol. MSG_OOB Send data as out-of-band data. Valid only for sockets with an address family of AF_INET or AF_INET6 and type SOCK_STREAM. MSG_DONTROUTE Bypass routing. Valid only for sockets with address family of AF_INET or AF_INET6. It is ignored for other address families.
Authorities
No authorization is required.
Return Value
send() returns an integer. Possible values are:
- -1 (unsuccessful)
- n (successful), where n is the number of bytes sent.
Error Conditions
When send() fails, errno can be set to one of the following:
[EACCES] | Permission denied.
This error code indicates one of the following:
|
[EBADF] | Descriptor not valid. |
[ECONNREFUSED] | The destination socket refused an attempted
connect operation.
This error code can only be returned on sockets that use a connectionless transport service. |
[EDESTADDRREQ] | Operation requires destination address.
A destination address has not been associated with the socket pointed to by the socket_descriptor parameter. This error code can only be returned on sockets that use a connectionless transport service. |
[EFAULT] | Bad address.
The system detected an address which was not valid while attempting to access the buffer parameter. |
[EHOSTDOWN] | A remote host is not available.
This error code can only be returned on sockets that use a connectionless transport service. |
[EHOSTUNREACH] | A route to the remote host is not available.
This error code can only be returned on sockets that use a connectionless transport service. |
[EINTR] | Interrupted function call. |
[EINVAL] | Parameter not valid.
The buffer_length parameter specifies a negative value. |
[EIO] | Input/output error. |
[EMSGSIZE] | Message size out of range.
The data to be sent could not be sent atomically because the size specified by buffer_length is too large. |
[ENETDOWN] | The network is not currently available.
This error code can only be returned on sockets that use a connectionless transport service. |
[ENETUNREACH] | Cannot reach the destination network.
This error code can only be returned on sockets that use a connectionless transport service. |
[ENOBUFS] | There is not enough buffer space for the
requested operation. |
[ENOTCONN] | Requested operation requires a connection.
This error code can only be returned on sockets that use a connection-oriented transport service. |
[ENOTSOCK] | The specified descriptor does not reference a
socket. |
[EOPNOTSUPP] | Operation not supported.
This error code indicates one of the following:
|
[EPIPE] | Broken pipe. |
[EUNATCH] | The protocol required to support the specified
address family is not available at this time. |
[EUNKNOWN] | Unknown system state. |
[EWOULDBLOCK] | Operation would have caused the thread to be suspended. |
Error Messages
Message ID | Error Message Text |
---|---|
CPE3418 E | Possible APAR condition or hardware failure. |
CPF9872 E | Program or service program &1 in library &2 ended. Reason code &3. |
CPFA081 E | Unable to set return value or error code. |
Usage Notes
- send() only works with sockets on which a connect() has
been issued, since it does not allow the caller to specify a destination
address.
- To broadcast on an AF_INET socket, the socket option
SO_BROADCAST must be set (with a setsockopt()).
- When using a connection-oriented transport service, all errors except
[EUNATCH] and [EUNKNOWN] are mapped to
[EPIPE] on an output operation when either of the following
occurs:
- A connection that is in progress is unsuccessful.
- An established connection is broken.
- A connection that is in progress is unsuccessful.
- When you develop in C-based languages and an application is compiled with the _XOPEN_SOURCE macro defined to the value 520 or greater, the send() API is mapped to qso_send98().
Related Information
- _XOPEN_SOURCE--Using _XOPEN_SOURCE for the UNIX 98
compatible interface
- fcntl()--Perform File Control Command
- ioctl()--Perform I/O Control Request
- sendto()--Send Data
- sendmsg()--Send Data or Descriptors or Both
- write()--Write to Descriptor
- writev()--Write to Descriptor Using Multiple Buffers
API introduced: V3R1
Top | UNIX-Type APIs | APIs by category |