套接字中的 read() 可以返回 EWOULDBLOCK 吗?

标签 c linux sockets epoll

我的代码使用 epoll 进行多路复用。遇到 EPOLLIN 后,它从就绪套接字中读取一个字节。

read(fd, &onebyte, 1);

上面的行能返回EWOULDBLOCK吗?

最佳答案

是的,

Errors:

...

EAGAIN or EWOULDBLOCK

The file descriptor fd refers to a socket and has been marked nonblocking (O_NONBLOCK), and the read would block. POSIX.1-2001 allows either error to be returned for this case, and does not require these constants to have the same value, so a portable application should check for both possibilities

引用: the read() man description

关于套接字中的 read() 可以返回 EWOULDBLOCK 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50784220/

相关文章:

C: switch 中需要整数表达式而不是 XY

c - %d 长整型

Python找不到openCV

linux - 在 unix 脚本中创建变量

c# - 无法弄清楚如何让Socket接收数据C#

在 Linux 上使用 AMD APP SDK 编译/构建 OpenCL 程序

C 表达式必须具有指向结构或 union 类型的指针

python 在启动树莓派时运行时将输出保存到文件

Linux无法通过管道获取数据

sockets - 是原始套接字数据报套接字吗?