tags:

views:

610

answers:

3

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

+5  A: 

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.

paxdiablo
+3  A: 

Platform depended, you can see some of them in Google Code Search

Shay Erlichmen
@Shay, are you aware that your link doesn't work (but it does in preview mode) - I downvoted you for that but, seeing as it's probably an SO bug, I'll reverse that. My apologies.
paxdiablo
@Pax, fixed, 10x
Shay Erlichmen
+4  A: 

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;
ok, Nice. I see the answer. FD_SETSIZE! That is how many listening sockets I can have. (*8)
Flinkman
on windows you can have 64
torial