-
-
Notifications
You must be signed in to change notification settings - Fork 45
Open
Description
The socket_status struct wraps the return value from the network operations and provides an operator bool():
Lines 580 to 585 in 9db92fb
| ///implicitly convert this object to const bool (as the status should not change) | |
| operator bool() const | |
| { | |
| //See the above enum: every value <= 0 correspond to an error, and will return false. Every value > 0 returns true | |
| return value > 0; | |
| } |
Unfortunately, this makes the following code behave rather unobvious:
auto status = my_sock.recv(...);
if (status != socket_status::valid) { cout << "Error!"; }One is tempted to think that this code checks whether status is socket_status::valid, but this is not what happens. At least under MSVC, this is equivalent to
if (status.operator bool() != static_cast<bool>(socket_status::valid))which basically turns it into a check if the resulting status is positive (i.e. valid, wouldblock, connection closed etc.).
In
Line 973 in 9db92fb
| if (connect(curr_addr, timeout, false) != socket_status::valid) |
Line 996 in 9db92fb
| if (connect(curr_addr, timeout, false) != socket_status::valid) |
I am not entirely sure whether this is a compiler bug or a bug in kissnet, but I do recommend to just drop the operator bool() entirely.
chaoticbob, skelleher, stijnb1234, bmahlbrand, EugeneYo and 3 more
Metadata
Metadata
Assignees
Labels
No labels