gtpc1m4hTransmission Control Protocol/Internet Protocol

write -- Write Data on a Connected Socket

Note

This description applies only to sockets. See TPF C/C++ Language Support User's Guide for more information about the write function for files.

The write function writes data on a socket with descriptor s. The write function applies only to connected sockets.

Format

#include    <socket.h>
int         write(int s,
                  char *buf,
                  int len);

s
The socket descriptor.

buf
Pointer to the buffer holding the data to be written.

len
Length of the message pointed to by the msg parameter.

When using TCP/IP offload support:

When using TCP/IP native stack support:

Normal Return

If it succeeds, the function returns the number of bytes.

Error Return

A return code equal to -1 indicates an error. You can get the specific error code by calling sock_errno. See Appendix C, Socket Error Return Codes for more information about socket errors.

Note:
Unless otherwise stated in the description, the following error codes can be returned for either TCP/IP offload support or TCP/IP native stack support.

Value
Description

SOCFAULT
Using buf and len results in an attempt to access a protected address space. This error code is returned only for TCP/IP offload support.

SOCNOBUFS
Buffer space is not available to send the message.

SOCNOTSOCK
The s parameter is not a valid socket descriptor.

SOCINVAL
An invalid length was specified.

SOCWOULDBLOCK
The s parameter is in nonblocking mode and no buffer space is available to hold the message to be sent.

SOCNOTCONN
The socket is not connected.

EIBMIUCVERR
An error occurred when the function call was sent to the offload device. This error code is returned only for TCP/IP offload support.

E1052STATE
The socket was closed because the system was in or cycling down to 1052 state.

EINACT
All offload devices associated with the socket descriptor have been disconnected. The socket is closed. This error code is returned only for TCP/IP offload support.

EINACTWS
An offload device associated with the socket descriptor has been disconnected. The socket is still available. This error code is returned only for TCP/IP offload support.

ESYSTEMERROR
A system error has occurred and closed the socket.

SOCMSGSIZE
The message was too large to be sent. This error code is returned only for TCP/IP native stack support.

SOCTIMEDOUT
The operation timed out. The socket is still available. This error code is returned only for TCP/IP native stack support.

Programming Considerations

Examples

In the following example, a 100-byte message is written to socket server_sock.

#include <socket.h>

·
·
·
int server_sock; char send_msg[100];
·
·
·
if (write(server_sock,send_msg,sizeof(send_msg)) < 0) printf("error in writing on stream socket\n");

Related Information