linux read write函数

Linux read()函数详解
本文详细介绍了Linux系统中read()函数的功能与使用方法。read()函数用于从指定文件描述符中读取数据到缓冲区中,支持阻塞与非阻塞两种模式。文章解释了在不同情况下read()函数的行为及返回值的意义。

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。
表示需要重新读取,不代表错误。

转载于:https://www.cnblogs.com/elseliving/p/7895268.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值