Sunday, September 4, 2011

Using FD_SET Macro

select FD_SET

After you have a file descriptor set initialized with the FD_ZERO macro, the next thing you want to accomplish is to register some file descriptors in it. This can be done with the FD_SET macro. The following example shows how a socket number c can be registered in a set named read_socks:

Example

int c;             /* Client socket */
fd_set read_socks; /* Read set */
. . .
FD_SET(c, &read_socks);

After calling FD_SET, a bit has registered interest in the corresponding file descriptor within the referenced set.

No comments:

Post a Comment