zkSockRead - read from a socket
#include "
zkSysSocket.h" ssize_t zkSockRead(int socket, void *buf, size_t nbyte);
The zkSockRead() function attempts to read nbyte bytes from the socket associated with the open socket descriptor, socket, into the buffer pointed to by buf.
If nbyte is 0, zkSockRead() will return 0 and have no other results.
If the value of nbyte is greater than {SSIZE_MAX}, the result is implementation-dependent.
Upon successful completion, where nbyte is greater than 0, zkRead() will return the number of bytes read. This number will never be greater than nbyte. The value returned may be less than nbyte if the number of bytes left in the file is less than nbyte. The value may also be less than nbyte under additional, implementation-defined circumstances. Consult your target platform's documentation for more information.
If a zkSockRead() is interrupted by a signal before it reads any data, it will return -1 with errno set to [EINTR].
If a zkSockRead() is interrupted by a signal after it has successfully read some data, it will return the number of bytes read.
If a zkSockRead() is equivalent to zkRecv() with no flags set.
Upon successful completion, zkSockRead returns a non-negative integer indicating the number of bytes actually read. Otherwise, the functions return -1 and set errno to indicate the error.
The zkSockRead() functions will fail if:
- [EAGAIN]
- The O_NONBLOCK flag is set for the file descriptor and the process would be delayed.
- [EBADF]
- The socket argument is not a valid socket descriptor open for reading.
- [EBADMSG]
- The file is a STREAM file that is set to control-normal mode and the message waiting to be read includes a control part.
- [EINTR]
- The read operation was terminated due to the receipt of a signal, and no data was transferred.
- [EINVAL]
- The STREAM or multiplexer referenced by socket is linked (directly or indirectly) downstream from a multiplexer.
- [EIO]
- A physical I/O error has occurred.
- [EIO]
- The process is a member of a background process attempting to read from its controlling terminal, the process is ignoring or blocking the SIGTTIN signal or the process group is orphaned. This error may also be generated for implementation-dependent reasons.
- [EISDIR]
- The socket argument refers to a directory and the implementation does not allow the directory to be read using zkSockRead().
- [EOVERFLOW]
- The file is a regular file, nbyte is greater than 0, the starting position is before the end-of-file and the starting position is greater than or equal to the offset maximum established in the open file description associated with socket.
The zkSockRead() function may fail if:
- [ENXIO]
- A request was made of a non-existent device, or the request was outside the capabilities of the device.
The zkSockRead() function may portably be used only with descriptors representing sockets. Any attempt to use it on a file, directory, FIFO, STREAMS file, terminal device file, character special file, or block special file is non-portable.