Quote:
Originally posted by cynthia
my code contains the lines
x=recv(...)
if(errno = WOULD_BLOCK)...
I want to avoid a situation that in this line errno will get a value from previous calls to recv().
how can I prevent such a mistake from happening?
do I need to flush error que in order to avoid that situation?
|
First off, you are assigning the value WOULD_BLOCK to errno, which is an error. (Note that errno can be implemented as a macro).
According to the standard, the only correct way to use errno is to set its value to 0 prior to a procedure call, and then test its value afterwards:
Code:
errno = 0;
x=recv(…);
if (errno == WOULD_BLOCK) …
Standard C does not implement an error “queue” that can be flushed as far as I am aware.
Hope that helps,
— Robert J. Lee