【计算机网络】多路转接之poll

poll也是一种linux中的多路转接方案(poll也是只负责IO过程中的"等")

解决:1.select的fd有上限的问题;2.每次调用都要重新设置关心的fd

一、poll的使用

int poll(struct pollfd * fds**,** nfds_t nfds**,** int timeout**);**


struct pollfd * fds:动态数组(struct pollfd类型的数组)

nfds_t nfds:数组元素个数

int timeout:>0 在timeout以内阻塞,否则非阻塞返回一次;=0 非阻塞等待;<0 阻塞等待

④ 返回值:同select(ret>0:返回有几个fd就绪了;ret==0:超时返回了;ret<0:调用失败)


struct pollfd结构体

struct pollfd { int fd; short events; short revents; };

events 用户告诉内核(输入型):要帮我关心fd的event事件 -> 输入看fd+events

revents 内核告诉用户(输出型):你关心的fd有哪些事已经就绪了 -> 输出看fd+revents

events和revents的取值

二、poll的特点

1.输入输出分离:poll不需要对参数进行重新设定

2.自定义数组个数:解决select等待fd有上限的问题

3.poll需要遍历整个struct pollfd *****fds数组 -> 为了解决这种问题 -> epoll

相关推荐
B1118521Y463 小时前
flask的使用
后端·python·flask
悟能不能悟3 小时前
js闭包问题
开发语言·前端·javascript
潼心1412o4 小时前
C语言(长期更新)第15讲 指针详解(五):习题实战
c语言·开发语言
xuxie134 小时前
SpringBoot文件下载(多文件以zip形式,单文件格式不变)
java·spring boot·后端
bantinghy4 小时前
Linux系统TCP/IP网络参数优化
linux·网络·tcp/ip
星期天要睡觉5 小时前
Linux 综合练习
linux·运维·服务器
重生成为编程大王5 小时前
Java中的多态有什么用?
java·后端
Murphy_lx5 小时前
Lambda表达式
开发语言·c++
saynaihe5 小时前
proxmox8升级到proxmox9
linux·运维·服务器
yangpipi-5 小时前
C++并发编程-23. 线程间切分任务的方法
开发语言·c++