IO复用 select Demo
来源:互联网 发布:中国帝国 知乎 编辑:程序博客网 时间:2024/06/10 13:26
1 等待键盘输入,输出读入的字节数和读入的内容
#include <sys/types.h>#include <sys/time.h>#include <stdio.h>#include <fcntl.h>#include <sys/ioctl.h>#include <unistd.h>#include <stdlib.h>int main(){ char buffer[11111]; int result,nread; fd_set inputs, testfds; struct timeval timeout; FD_ZERO(&inputs); FD_SET(0,&inputs); while (true) { testfds = inputs; timeout.tv_sec = 2; timeout.tv_usec = 5000; result = select(FD_SETSIZE,&testfds,(fd_set *)0,(fd_set *)0,&timeout); switch(result) { case 0: printf("timeout\n"); break; case -1: perror("select"); break; default: if (FD_ISSET(0,&testfds)) { ioctl(0, FIONREAD, &nread); if (nread == 0) { printf("done\n"); exit(0); } nread = read(0,buffer,nread); buffer[nread] = 0; printf("read %d from keyboard: %s\n",nread,buffer); } break; } } return 0;}
0 0
- IO复用 select Demo
- io复用select pselect
- IO复用:select函数
- IO复用:select函数
- IO复用select模型
- select多路IO复用
- select,epoll 多路IO复用
- linux编程---IO复用---select
- php socket select IO复用
- select与epoll,多路IO复用
- IO复用 select函数使用实例
- IO复用: select 和poll 到epoll
- select、poll、epoll三组IO复用
- IO复用,select、poll、epoll综述
- UNPv1第六章:IO复用select&poll
- winsocket c++ IO复用 之Select
- IO复用: select 和poll 到epoll
- IO复用(select)代码实现
- 前端必读:浏览器内部工作原理
- request的setAttribute()怎么用的?
- iOS:SVN出错 Description : The working copy is locked due to a previous error
- C++的字节对齐
- Android开发:界面布局的基本使用
- IO复用 select Demo
- poj 1012 约瑟夫问题
- C++primer(第四版)复习笔记—第一篇:基本语言
- CV 资源汇总
- C++11实现多线程 互斥锁与资源竞争问题
- text和checkbox只读属性的设置
- (转)数据库范式(1NF 2NF 3NF BCNF)详解一
- YARN的 Resource Manager的作用
- 设备驱动程序通知应用程序的几种方法