z/OS Communications Server: IP Sockets Application Programming Interface Guide and Reference
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


write()

z/OS Communications Server: IP Sockets Application Programming Interface Guide and Reference
SC27-3660-00

The write() call writes data from a buffer on a socket with descriptor s. The write() call applies only to connected sockets.

This call writes up to len bytes of data.

If there is not enough available buffer space to hold the socket data to be transmitted and the socket is in blocking mode, write() blocks the caller until more buffer space is available. If the socket is in nonblocking mode, write() returns a -1 and sets errno to EWOULDBLOCK. See fcntl() or ioctl() to set nonblocking mode.

For datagram sockets, this call sends the entire datagram, providing the datagram can fit into the TCP/IP buffers. Stream sockets act like streams of information with no boundaries separating data. For example, if an application wants to send 1000 bytes, each call to this function can send 1 byte, or 10 bytes, or the entire 1000 bytes. Therefore, applications using stream sockets should place this call in a loop, and call this function until all data has been sent.

#include <manifest.h>
#include <socket.h>
 
int write(int s, char *buf, int len)
Parameter
Description
s
Socket descriptor.
buf
Points to the buffer holding the data to be written.
len
Length in bytes of buf.

Return values

If successful, the number of bytes written is returned. The value -1 indicates an error. Errno identifies the specific error.
Errno
Description
EBADF
Indicates that s is not a valid socket descriptor.
EFAULT
Using the buf and len parameters would result in an attempt to access storage outside the caller address space.
ENOBUFS
Buffer space is not available to send the message.
EWOULDBLOCK
Indicates that s is in nonblocking mode and there is not enough space in TCP⁄IP to accept the data.

Related calls

connect(), fcntl(), getsockopt(), ioctl(), read(), readv() recv(), recvfrom(), recvmsg(), select(), selectex(), send(), sendmsg(), sendto(), setsockopt(), socket(), writev()

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014