在c中使用套接字时,FD_SET和FD_ISSET后面的数据结构是什么?

发布于 2024-07-16 02:53:43 字数 44 浏览 4 评论 0原文

使用套接字时,FD_SET 和 FD_ISSET 宏背后的数据结构是什么?

What data structure is behind FD_SET and FD_ISSET macro when working with sockets?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

看春风乍起 2024-07-23 02:53:44

原型:

void FD_SET(int fd, fd_set* fdset);
int FD_ISSET(int fd, fd_set* fdset);

来自 sys/select.h

typedef struct fd_set {
  u_int  fd_count;
  SOCKET fd_array[FD_SETSIZE];
} fd_set;

Prototypes:

void FD_SET(int fd, fd_set* fdset);
int FD_ISSET(int fd, fd_set* fdset);

From sys/select.h

typedef struct fd_set {
  u_int  fd_count;
  SOCKET fd_array[FD_SETSIZE];
} fd_set;
放赐 2024-07-23 02:53:44

我似乎记得它只是一个位掩码。 字符数组(或其他一些基本类型),其中字符的每一位代表每个文件描述符的状态。

如果某些实现允许可变大小的结构,那么它们也有一个限制变量,但我见过的大多数(通常是较旧的)只允许最大数量的文件描述符。

然而,实现可以自由地使用它想要的任何数据结构,只要它提供 FD_* 宏或函数来正确初始化和更改它们。

I seem to recall it's just a bitmask. An array of chars (or some other basic type) where each bit of the char represents the state of each file descriptor.

Some implementations also have a limit variable if they allow variable sized structures but most that I've seen (and these are generally the older ones) simply allow for the largest number of file descriptors.

However, an implementation is free to use whatever data structure it wants as long as it provides the FD_* macros or functions to properly initialize and change them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文