Take the 2-minute tour ×

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

share|improve this question
add comment

3 Answers

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.

share|improve this answer
add comment

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

share|improve this answer
@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 Apr 1 '09 at 8:42
@Pax, fixed, 10x –  Shay Erlichmen Apr 1 '09 at 8:58
add comment


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;
share|improve this answer
ok, Nice. I see the answer. FD_SETSIZE! That is how many listening sockets I can have. (*8) –  Flinkman Apr 1 '09 at 18:01
on windows you can have 64 –  torial Jun 23 '09 at 4:56
add comment

Your Answer


