本文主要是介绍玩下linux中的的poll函数------可以用任何描述符号fd而不限于网络socket,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
前面我们玩了linux中的select函数, 今天我们来介绍一个与之类似的函数, 作用就是做轮询检测, 建议先看select, 再看poll. 至于函数原型和返回值, 就没有必要单独说了, 网上一搜一大堆。
直接上菜:
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <malloc.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/ioctl.h>
#include <stdarg.h>
#include <fcntl.h>
#include <fcntl.h>
#include <sys/poll.h> #if 0
struct pollfd
{int fd; //文件描述符short events; //请求的事件short revents; //返回的事件
};
#endifint main()
{pollfd fds[10];fds[0].fd = STDIN_FILENO; // 标准输入描述符fds[0].events = POLLIN; // 检测读int nfds = 1; // 待监听的描述符的个数int timeoutMS = 5000; // 毫秒int i
这篇关于玩下linux中的的poll函数------可以用任何描述符号fd而不限于网络socket的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!