Linux网络编程/poll服务器
来源:互联网 发布:南京行知基地 编辑:程序博客网 时间:2024/06/08 13:36
一、编写poll服务器
对Pool服务器的了解:
pollfd结构包含了要监视的event和发生的event,不在使用select”参数-值”传递的方式,同时,pollfd并没有最大数量限制。和select函数一样,poll返回后,需要轮询pollfd来获取就绪的描述符。
#include<stdio.h>#include<poll.h>int main(){ struct pollfd pfd; pfd.fd = 0; pfd.events = POLLIN; pfd.revents = 0; int timeout = -1; while(1){ switch(poll(&pfd,1, timeout)){ case -1: perror("poll"); break; case 0: printf("timeout...\n"); break; default: { if (pfd.revents & POLLIN){ char buf[1024]; ssize_t s = read(0, buf, sizeof(buf)-1); if (s > 0) { buf[s] = 0; printf("echo# %s\n", buf); } } } break; } } return 0;}
运行结果:
总结:poll函数,解决文件描述符的上限问题,但是数量过大后性能也是下降;poll一次,不需要重新设置参数,pollfd结构体中一个结构体对应一个文件描述符。
阅读全文
0 0
- Linux网络编程/poll服务器
- Linux网络编程poll模型
- Linux网络编程poll模型
- linux网络编程之 poll
- linux网络编程之 poll
- Linux网络编程之poll
- linux网络编程之poll
- Linux网络编程——tcp并发服务器(poll实现)
- Linux网络编程——tcp并发服务器(poll实现)
- Linux【网络编程】——I/O多路转接之Poll服务器
- Linux网络编程——tcp并发服务器(poll实现)
- Linux网络编程——tcp并发服务器(poll实现)
- linux网络编程 select,poll,epoll模型
- linux网络编程poll与epoll区别
- Linux网络编程--poll()和ppoll()函数
- poll服务器编程综合
- 网络编程 poll
- 【Linux网络编程】基于TCP流 I/O多路转接(poll) 的高性能http服务器
- 浅谈命令行操作数据库
- JDK5中的Callable与Future的应用:获取一个线程的运行结果
- 数据结构之树的存储结构
- Google map 搜索+点击地图添加标注点 并且返回坐标
- SQLServer服务器数据库之间的数据操作(完整版)
- Linux网络编程/poll服务器
- Leetcode 357. Count Numbers with Unique Digits
- 第二篇:salesforce自定义link/button并执行js
- php组合模式
- idea从svn中导入多模块项目
- viewPager fragment 懒加载
- ZXing二维码扫描
- for简单小训练
- [BZOJ]4491: 我也不知道题目名字是什么 线段树(差分)