[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]

Technical Reference: Communications, Volume 2


send Subroutine

Purpose

Sends messages from a connected socket.

Library

Standard C Library (libc.a)

Syntax

#include <sys/types.h>
#include <sys/socketvar.h>
#include <sys/socket.h>


int send (Socket,
Message, Length, Flags)
int Socket;
const void * Message;
size_t Length;
int Flags;

Description

The send subroutine sends a message only when the socket is connected. This subroutine on a socket is not thread safe. The sendto and sendmsg subroutines can be used with unconnected or connected sockets.

To broadcast on a socket, first issue a setsockopt subroutine using the SO_BROADCAST option to gain broadcast permissions.

Specify the length of the message with the Length parameter. If the message is too long to pass through the underlying protocol, the system returns an error and does not transmit the message.

No indication of failure to deliver is implied in a send subroutine. A return value of -1 indicates some locally detected errors.

If no space for messages is available at the sending socket to hold the message to be transmitted, the send subroutine blocks unless the socket is in a nonblocking I/O mode. Use the select subroutine to determine when it is possible to send more data.

Parameters


Socket Specifies the unique name for the socket.
Message Points to the address of the message to send.
Length Specifies the length of the message in bytes.
Flags Allows the sender to control the transmission of the message. The Flags parameter used to send a call is formed by logically ORing one or both of the values shown in the following list:

MSG_OOB
Processes out-of-band data on sockets that support SOCK_STREAM communication.

MSG_DONTROUTE
Sends without using routing tables.

MSG_MPEG2
Indicates that this block is a MPEG2 block. This flag is valid SOCK_CONN_DGRAM types of sockets only.

Return Values

Upon successful completion, the send subroutine returns the number of characters sent.

If the send subroutine is unsuccessful, the subroutine handler performs the following functions:

Error Codes

The subroutine is unsuccessful if any of the following errors occurs:

EBADF The Socket parameter is not valid.
ENOTSOCK The Socket parameter refers to a file, not a socket.
EFAULT The Address parameter is not in a writable part of the user address space.
EWOULDBLOCK The socket is marked nonblocking, and no connections are present to be accepted.

Implementation Specifics

The send subroutine is part of Base Operating System (BOS) Runtime.

The socket applications can be compiled with COMPAT_43 defined. This will make the sockaddr structure BSD 4.3 compatible. For more details refer to socket.h.

Related Information

The connect subroutine, getsockopt subroutine, recv subroutine, recvfrom subroutine, recvmsg subroutine, select subroutine, sendmsg subroutine, sendto subroutine, setsockopt subroutine. shutdown subroutine, socket subroutine.

Sockets Overview and Understanding Socket Data Transfer in AIX 5L Version 5.1 Communications Programming Concepts.


[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]