Reputation: 28269
I'm learning socket programming using book Unix Network Programming
. Here are two pieces of code from this book:
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
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
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