gpt4 book ai didi

c - 电平触发还是边沿触发?

转载 作者:太空狗 更新时间:2023-10-29 11:03:42 31 4
gpt4 key购买 nike

我有一个服务器应用程序,它监听一个端口,接受 (TCP) 对等连接,然后为每个套接字它

1) 读取(不超过30字节的数据)

2) 发送(1字节确认)

3) 读取(不超过2K)

4) 发送(1字节确认)

5) 关闭(连接)

我在我的应用程序中使用了 epoll 循环。我希望 epoll_wait 仅当所有数据都从对等方到达时返回(带有带有 EPOLLIN 标志的事件列表),以便我可以使用单个 read/recv 进行读取 调用数组。如果某个套接字 fd 上没有收到所有数据,我不希望 epoll 将此 fd 添加到事件列表中。

据我了解 epoll 的水平触发和边缘触发模式之间的差异,可以使用具有非阻塞套接字和有限状态的边缘触发 epoll 来实现此行为跟踪步骤。

如果我对边缘触发选项有误,请纠正我。任何的想法?

最佳答案

epoll_wait 报告套接字准备好读取之前,似乎无法设置传入套接字缓冲区中可用的最小字节数。

man socket(7) :

SO_RCVLOWAT and SO_SNDLOWAT

Specify the minimum number of bytes in the buffer until the socket layer will pass the data to the protocol (SO_SNDLOWAT) or the user on receiving (SO_RCVLOWAT). These two values are initialized to 1. SO_SNDLOWAT is not changeable on Linux (setsockopt(2) fails with the error ENOPROTOOPT). SO_RCVLOWAT is changeable only since Linux 2.4. The select(2) and poll(2) system calls currently do not respect the SO_RCVLOWAT setting on Linux, and mark a socket readable when even a single byte of data is available. A subsequent read from the socket will block until SO_RCVLOWAT bytes are available.

除非手册页已过时。

关于c - 电平触发还是边沿触发?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37619741/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com