select fd_set
2019独角兽企业重金招聘Python工程师标准>>>
fd_set 结构,是一个数字。 文件描述符fd的值 不能超过1024,而不是数量不能超过1024。
在开发打开句柄多的程序时,最好不要使用select。否则就使用多进程开发。
/usr/include/X11 Xpoll.h 文件
#ifndef _XPOLL_H_
#define _XPOLL_H_
#ifndef WIN32
#ifndef USE_POLL
#include <X11/Xos.h>
#include <sys/select.h> /* Get the FD_* macros. */
#include <X11/Xmd.h>
#ifdef CSRG_BASED
#include <sys/param.h>
# if BSD < 199103
typedef long fd_mask;
# endif
#endif
#define XFD_SETSIZE 256
#ifndef FD_SETSIZE
#define FD_SETSIZE XFD_SETSIZE
#endif
#ifndef NBBY
#define NBBY 8 /* number of bits in a byte */
#endif
#ifndef NFDBITS
#define NFDBITS (sizeof(fd_mask) * NBBY) /* bits per mask */
#endif
#ifndef howmany
#define howmany(x,y) (((x)+((y)-1))/(y))
#endif
#if defined(BSD) && BSD < 198911
typedef struct fd_set {
fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
} fd_set;
#endif
# define Select(n,r,w,e,t) select(n,(fd_set*)r,(fd_set*)w,(fd_set*)e,(struct timeval*)t)
#define __X_FDS_BITS __fds_bits
#ifndef __FDS_BITS
# define __FDS_BITS(p) ((p)->__X_FDS_BITS)
#endif
#define __XFDS_BITS(p, n) (__FDS_BITS(p))[n]
#ifndef FD_SET
#define FD_SET(n, p) (__XFDS_BITS(p, ((n)/NFDBITS)) |= ((fd_mask)1 << ((n) % NFDBITS)))
#endif
#ifndef FD_CLR
#define FD_CLR(n, p) (__XFDS_BITS((p), ((n)/NFDBITS)) &= ~((fd_mask)1 << ((n) % NFDBITS)))
#endif
#ifndef FD_ISSET
#define FD_ISSET(n, p) ((__XFDS_BITS((p), ((n)/NFDBITS))) & ((fd_mask)1 << ((n) % NFDBITS)))
#endif
#ifndef FD_ZERO
#define FD_ZERO(p) bzero((char *)(p), sizeof(*(p)))
#endif
/*
* The howmany(FD_SETSIZE, NFDBITS) computes the number of elements in the
* array. before accessing an element in the array we check it exists.
* If it does not exist then the compiler discards the code to access it.
*/
#define XFD_ANYSET(p) \
((howmany(FD_SETSIZE, NFDBITS) > 0 && (__XFDS_BITS(p, 0))) || \
(howmany(FD_SETSIZE, NFDBITS) > 1 && (__XFDS_BITS(p, 1))) || \
(howmany(FD_SETSIZE, NFDBITS) > 2 && (__XFDS_BITS(p, 2))) || \
(howmany(FD_SETSIZE, NFDBITS) > 3 && (__XFDS_BITS(p, 3))) || \
(howmany(FD_SETSIZE, NFDBITS) > 4 && (__XFDS_BITS(p, 4))) || \
(howmany(FD_SETSIZE, NFDBITS) > 5 && (__XFDS_BITS(p, 5))) || \
(howmany(FD_SETSIZE, NFDBITS) > 6 && (__XFDS_BITS(p, 6))) || \
(howmany(FD_SETSIZE, NFDBITS) > 7 && (__XFDS_BITS(p, 7))))
#define XFD_COPYSET(src,dst) { \
int __i__; \
for (__i__ = 0; __i__ < howmany(FD_SETSIZE, NFDBITS); __i__++) \
__XFDS_BITS((dst), __i__) = __XFDS_BITS((src), __i__); \
}
#define XFD_ANDSET(dst,b1,b2) { \
int __i__; \
for (__i__ = 0; __i__ < howmany(FD_SETSIZE, NFDBITS); __i__++) \
__XFDS_BITS((dst), __i__) = ((__XFDS_BITS((b1), __i__)) & (__XFDS_BITS((b2), __i__))); \
}
#define XFD_ORSET(dst,b1,b2) { \
int __i__; \
for (__i__ = 0; __i__ < howmany(FD_SETSIZE, NFDBITS); __i__++) \
__XFDS_BITS((dst), __i__) = ((__XFDS_BITS((b1), __i__)) | (__XFDS_BITS((b2), __i__))); \
}
#define XFD_UNSET(dst,b1) { \
int __i__; \
for (__i__ = 0; __i__ < howmany(FD_SETSIZE, NFDBITS); __i__++) \
__XFDS_BITS((dst), __i__) &= ~(__XFDS_BITS((b1), __i__)); \
}
#else /* USE_POLL */
#include <sys/poll.h>
#endif /* USE_POLL */
#else /* WIN32 */
#define XFD_SETSIZE 256
#ifndef FD_SETSIZE
#define FD_SETSIZE XFD_SETSIZE
#endif
#include <X11/Xwinsock.h>
#define Select(n,r,w,e,t) select(0,(fd_set*)r,(fd_set*)w,(fd_set*)e,(struct timeval*)t)
#define XFD_SETCOUNT(p) (((fd_set FAR *)(p))->fd_count)
#define XFD_FD(p,i) (((fd_set FAR *)(p))->fd_array[i])
#define XFD_ANYSET(p) XFD_SETCOUNT(p)
#define XFD_COPYSET(src,dst) { \
u_int __i; \
FD_ZERO(dst); \
for (__i = 0; __i < XFD_SETCOUNT(src) ; __i++) { \
XFD_FD(dst,__i) = XFD_FD(src,__i); \
} \
XFD_SETCOUNT(dst) = XFD_SETCOUNT(src); \
}
#define XFD_ANDSET(dst,b1,b2) { \
u_int __i; \
FD_ZERO(dst); \
for (__i = 0; __i < XFD_SETCOUNT(b1) ; __i++) { \
if (FD_ISSET(XFD_FD(b1,__i), b2)) \
FD_SET(XFD_FD(b1,__i), dst); \
} \
}
#define XFD_ORSET(dst,b1,b2) { \
u_int __i; \
if (dst != b1) XFD_COPYSET(b1,dst); \
for (__i = 0; __i < XFD_SETCOUNT(b2) ; __i++) { \
if (!FD_ISSET(XFD_FD(b2,__i), dst)) \
FD_SET(XFD_FD(b2,__i), dst); \
} \
}
/* this one is really sub-optimal */
#define XFD_UNSET(dst,b1) { \
u_int __i; \
for (__i = 0; __i < XFD_SETCOUNT(b1) ; __i++) { \
FD_CLR(XFD_FD(b1,__i), dst); \
} \
}
/* we have to pay the price of having an array here, unlike with bitmasks
calling twice FD_SET with the same fd is not transparent, so be careful */
#undef FD_SET
#define FD_SET(fd,set) do { \
if (XFD_SETCOUNT(set) < FD_SETSIZE && !FD_ISSET(fd,set)) \
XFD_FD(set,XFD_SETCOUNT(set)++)=(fd); \
} while(0)
#define getdtablesize() FD_SETSIZE
#endif /* WIN32 */
#endif /* _XPOLL_H_ */
转载于:https://my.oschina.net/u/1445488/blog/351502
select fd_set相关推荐
- Linux下I/O多路转接之select --fd_set
fd_set 你终于还是来了,能看到这个标题进来的,我想,你一定是和我遇到了一样的问题,一样的疑惑,接下来几个小时,我一定竭尽全力,写出我想说的,希望也正是你所需要的: 关于Linux下I/O多路转接 ...
- C/C++ select fd_set解释
将套接口socket添加到fd_set 队列里面 后者可以通过传递给select函数来监听这一组套接口的状态,例如套接口上是否有数据传来等状态 select()机制中提供一fd_set的数据结构,实际 ...
- 彻底解释Linux select的1024限制(select真的受1024限制吗?不!)
很多很多年前,我被面试 为什么select调用最多只支持1024个文件描述符? 我没有答出来,我甚至不知道select到底是干什么的. 又过了很多年,我用这个问题面试了别人- 在当时,我心里已经有了会 ...
- 《嵌入式系统 – 玩转ART-Pi开发板(基于RT-Thread系统)》第9章 基于Select/Poll实现并发服务器(二)
基于Select/Poll实现并发服务器(一) 9.3 Select/Poll概述 在LWIP中,如果要实现并发服务器,可以基于Sequentaial API来实现,这种方式需要使用多线程,也就是为每 ...
- select函数的作用!
select()的机制中提供一fd_set的数据结构,实际上是一long类型的数组, 每一个数组元素都能与一打开的文件句柄(不管是Socket句柄,还是其他 文件或命名管道或设备句柄)建立联系,建立联 ...
- select和epoll的区别详解
1. 名词解释 1.1 文件描述符fd 文件描述符(File descriptor)是计算机科学中的一个术语,是一个用于表述指向文件的引用的抽象化概念. 文件描述符在形式上是一个非负整数.实际上,它是 ...
- windows socket编程入门示例3
// Lock.h #ifndef _Lock_H #define _Lock_H #include <windows.h>class CriticalSection { private: ...
- PM2.5检测 -- PMS7003 采集和 MQTT 传输
下一篇文章里我们通过交叉编译生成了 libmosquitto.so.1 参看:MQTT再学习 -- 交叉编译与移植 之前有讲过MQTT客户端的测试,参看:MQTT再学习 -- 安装MQTT客户端及测试 ...
- linux编译测试代码,rtc在linux上的测试代码
点击(此处)折叠或打开 rtc在linux上的测试代码 . rtc应用很广泛,在PC机和嵌入式上面几乎都能看到.下面就用最简单的代码做一个演示.相应的分析请看linux源代码中的分析文档.代码如下: ...
最新文章
- 谷歌为语言AI模型推TensorFlow.Text
- python编写请求参数带文件_python requests 库请求带有文件参数的接口实例
- 网络推广软文浅谈网站优化过程中图片的优化技巧和注意事项!
- pthread调度策略,优先级和竞争范围
- 用 Python 和 OpenCV 检测图片上的条形码Detecting Barcodes in Images with Python and OpenCV
- java dexclassloader_DexClassLoader加载apk
- 1616: 最长回文串(马拉车算法)
- tf.contrib.slim add_arg_scope
- SAP Digital Asset Management by OpenText for CRM
- Java注解(Annotation)的学习
- pythonasyncio并发编程实战_python异步编程之asyncio(百万并发)
- Python递归文件夹遍历所有文件夹及文件
- python 可视化 画直线_用Python画江苏省地图,实现各地级市数据可视化
- 脚本精灵服务器引擎数据为空,脚本精灵服务器
- C语言---14文件操作---01文件内容的顺序读写
- android按键精灵源码,按键精灵手机版网络验证源码适用安卓/苹果ios手机按键
- HashMap扩容机制源码分析
- uniapp 视频图片切换,视频高度宽度自适应
- 跌倒智能监测警报系统市场现状及未来发展趋势分析
- [0.0]-AutoSAR零基础学习-专栏介绍