Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sockets.c: Destinct pointers for restrict parameters #602

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mkuettle
Copy link

Avoid passing the same pointer twice for restrict parameters for select. Rather copy the object for the second argument.

Avoid passing the same pointer twice for `restrict` parameters for `select`. Rather copy the object for the second argument.
tv.tv_sec = timeout / 1000;
tv.tv_usec = (timeout % 1000) * 1000;
n = select(sock+1, &fds, NULL, &fds, &tv);
n = select(sock+1, &fds, NULL, &exceptfds, &tv);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

…and if select() sets a bit in exceptfds where is it checked in the following code?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I might have missed something there, but afaict nobody is checking fds currently.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. I am not familiar with the semantics of select() here, but wouldn't it be the same as passing NULL if the caller is not interested in the file descriptors anyway?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the manpage, NULL is equivalent to an empty set. So this is different, as it specifies a set with one fd set.

Regarding the checking of the result of select(): I can not claim to fully understand the code, but only a single fd is set in fds (FD_SET(sock, &fds);). I guess this fd is probed afterwards, so that the result of select() is not needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants