xingbin
xingbin

Reputation: 28269

The result of FD_ISSET without calling `select`

I'm learning socket programming using book Unix Network Programming. Here are two pieces of code from this book:

enter image description here

enter image description here

As we can see, it calls FD_ISSET after FD_SET without calling select function between them, what's the result? Will it be true if sockfd is writable?

PS: the source code http://www.masterraghu.com/subjects/np/introduction/unix_network_programming_v1.3/ch16lev1sec2.html

Upvotes: 0

Views: 174

Answers (2)

Some programmer dude
Some programmer dude

Reputation: 409166

Well there are 30 missing lines between the two snippets, how do we know that select isn't called there?

Besides that, the select function isn't doing anything special, it just clears descriptors from the sets.

If you call FD_SET(sockfd, &wset) directly followed by FD_ISSET(sockfd, &wset) then the FD_ISSET macro will simply evaluate to "true" (a non-zero integer value).

Upvotes: 1

Steffen Ullrich
Steffen Ullrich

Reputation: 123270

FD_SET just sets a bit in a bit mask and FD_ISSET checks this bit. These calls don't care if this bit represents a file descriptor or not, it is just an integer. If there is nothing in between these calls which manipulates the bit mask (i.e. no call of select) then the result of FD_ISSET reflects exactly what was set with FD_SET.

Upvotes: 3

Related Questions