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:

Authorities

No authorization is required.


Return Value

send() returns an integer. Possible values are:


Error Conditions

When send() fails, errno can be set to one of the following:



Error Messages



Usage Notes

  1. send() only works with sockets on which a connect() has been issued, since it does not allow the caller to specify a destination address.

  2. To broadcast on an AF_INET socket, the socket option SO_BROADCAST must be set (with a setsockopt()).

  3. 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.
    To get the actual error, use getsockopt() with the SO_ERROR option, or perform an input operation (for example, read()).

  4. 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



API introduced: V3R1