aboutsummaryrefslogtreecommitdiff
path: root/src/util/sock.h
diff options
context:
space:
mode:
authorVasil Dimov <vd@FreeBSD.org>2021-05-04 12:06:44 +0200
committerVasil Dimov <vd@FreeBSD.org>2022-06-09 13:34:27 +0200
commitcc74459768063a923fb6220a4f420eaf211aee7b (patch)
treed0d044422b29af67de3f064963024210f66c89d5 /src/util/sock.h
parente18fd4763e77d1e19208effa9f1a08c5b29fea8e (diff)
downloadbitcoin-cc74459768063a923fb6220a4f420eaf211aee7b.tar.xz
net: also wait for exceptional events in Sock::Wait()
This mimics closely `CConnman::SocketEvents()` and the underlying `poll(2)`.
Diffstat (limited to 'src/util/sock.h')
-rw-r--r--src/util/sock.h19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/util/sock.h b/src/util/sock.h
index dd2913a66c..e6419eb8ce 100644
--- a/src/util/sock.h
+++ b/src/util/sock.h
@@ -130,21 +130,28 @@ public:
/**
* If passed to `Wait()`, then it will wait for readiness to read from the socket.
*/
- static constexpr Event RECV = 0b01;
+ static constexpr Event RECV = 0b001;
/**
* If passed to `Wait()`, then it will wait for readiness to send to the socket.
*/
- static constexpr Event SEND = 0b10;
+ static constexpr Event SEND = 0b010;
+
+ /**
+ * Ignored if passed to `Wait()`, but could be set in the occurred events if an
+ * exceptional condition has occurred on the socket or if it has been disconnected.
+ */
+ static constexpr Event ERR = 0b100;
/**
* Wait for readiness for input (recv) or output (send).
* @param[in] timeout Wait this much for at least one of the requested events to occur.
* @param[in] requested Wait for those events, bitwise-or of `RECV` and `SEND`.
- * @param[out] occurred If not nullptr and `true` is returned, then upon return this
- * indicates which of the requested events occurred. A timeout is indicated by return
- * value of `true` and `occurred` being set to 0.
- * @return true on success and false otherwise
+ * @param[out] occurred If not nullptr and the function returns `true`, then this
+ * indicates which of the requested events occurred (`ERR` will be added, even if
+ * not requested, if an exceptional event occurs on the socket).
+ * A timeout is indicated by return value of `true` and `occurred` being set to 0.
+ * @return true on success (or timeout, if `occurred` of 0 is returned), false otherwise
*/
[[nodiscard]] virtual bool Wait(std::chrono::milliseconds timeout,
Event requested,