相关疑难解决方法(0)

send()总是发送整个缓冲区吗?

send() 应该返回发送的字节数或错误代码,但是我发现的所有示例都只检查错误代码,但不检查发送的字节数.

//typical example
int cnt=send(s,query,strlen(query),0);
if (cnt < 0) return(NULL);
//Hey, what about cnt < strlen(query)?
Run Code Online (Sandbox Code Playgroud)

c sockets linux

10
推荐指数
2
解决办法
3761
查看次数

为什么必须在边缘触发epoll函数中使用非阻塞fd?

我在网上读了文件abount edge触发的epoll函数,如下所示:

1. The file descriptor that represents the read side of a pipe (rfd) is registered on the epoll instance.
2. A pipe writer writes 2 kB of data on the write side of the pipe.
3. A call to epoll_wait(2) is done that will return rfd as a ready file descriptor.
4. The pipe reader reads 1 kB of data from rfd.
5. A call to epoll_wait(2) is done.
.......
.......
Run Code Online (Sandbox Code Playgroud)

使用epoll作为边缘触发(EPOLLET)接口的建议方法如下:i)使用非阻塞文件描述符ii)仅在read(2)或write(2)返回EAGAIN之后为事件调用epoll_wait.

我理解2,但我不知道为什么使用非阻塞文件描述符.

谁能解释为什么使用非阻塞文件描述符的原因?为什么在级别触发的epoll函数中使用阻塞文件描述符是可以的?

linux epoll nonblocking socket.io

4
推荐指数
1
解决办法
2656
查看次数

标签 统计

linux ×2

c ×1

epoll ×1

nonblocking ×1

socket.io ×1

sockets ×1