What data structure is behind FD_SET and FD_ISSET macro when working with sockets?
views:
610answers:
3
+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
2009-04-01 06:04:16
+3
A:
Platform depended, you can see some of them in Google Code Search
Shay Erlichmen
2009-04-01 06:04:25
@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
2009-04-01 08:42:44
@Pax, fixed, 10x
Shay Erlichmen
2009-04-01 08:58:39
+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;