aboutsummaryrefslogtreecommitdiff
path: root/src/util/sock.h
diff options
context:
space:
mode:
authorVasil Dimov <vd@FreeBSD.org>2021-04-13 12:31:49 +0200
committerVasil Dimov <vd@FreeBSD.org>2022-04-15 09:14:49 +0200
commit184e56d6683d05fc84f5153cfff83a2e32883556 (patch)
tree33fe88e870ac0196ecf245be57a02e98afb0d561 /src/util/sock.h
parente14f0fa6a346afecbb1d5470aef5226a8cc33e57 (diff)
downloadbitcoin-184e56d6683d05fc84f5153cfff83a2e32883556.tar.xz
net: add new method Sock::SetSockOpt() that wraps setsockopt()
This will help to increase `Sock` usage and make more code mockable.
Diffstat (limited to 'src/util/sock.h')
-rw-r--r--src/util/sock.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/util/sock.h b/src/util/sock.h
index 7510482857..dd2913a66c 100644
--- a/src/util/sock.h
+++ b/src/util/sock.h
@@ -115,6 +115,16 @@ public:
void* opt_val,
socklen_t* opt_len) const;
+ /**
+ * setsockopt(2) wrapper. Equivalent to
+ * `setsockopt(this->Get(), level, opt_name, opt_val, opt_len)`. Code that uses this
+ * wrapper can be unit tested if this method is overridden by a mock Sock implementation.
+ */
+ [[nodiscard]] virtual int SetSockOpt(int level,
+ int opt_name,
+ const void* opt_val,
+ socklen_t opt_len) const;
+
using Event = uint8_t;
/**