linux read write函数

http://man7.org/linux/man-pages/man2/read.2.html

ssize_t read(int fd, void *buf, size_t count);
read() attempts to read up to count bytes from file descriptor fd
into the buffer starting at buf.

read默认时阻塞的,功能是读取给定的len长度的字节到buf。

If the file offset is at or past the end of file, no bytes are read,
and read() returns zero.

如果读取完毕或者socket close了,那么返回0.

如果返回-1,表示错误,在errno中。

但是如果是socket并且在创建时被设置为非阻塞的,如果返回-1并且errno = EAGAIN。
表示需要重新读取,不代表错误。

posted @ 2017-11-25 14:45  elseliving的记录  阅读(386)  评论(0编辑  收藏  举报