aboutsummaryrefslogtreecommitdiff
path: root/src/util/sock.h
diff options
context:
space:
mode:
authorlaanwj <126646+laanwj@users.noreply.github.com>2022-06-28 13:39:51 +0200
committerlaanwj <126646+laanwj@users.noreply.github.com>2022-06-28 13:40:05 +0200
commitba29911e21c88f49780c6c87f94ff8ed6e764a9d (patch)
tree72300e73e31f4e14076e196a1a27203ab15bf9cb /src/util/sock.h
parent1b5610852e13f1fe41195dc072c8e92648ba1716 (diff)
parenta8d6abba5ec4ae2a3375e9be0b739f298899eca2 (diff)
downloadbitcoin-ba29911e21c88f49780c6c87f94ff8ed6e764a9d.tar.xz
Merge bitcoin/bitcoin#25426: net: add new method Sock::GetSockName() that wraps getsockname() and use it in GetBindAddress()
a8d6abba5ec4ae2a3375e9be0b739f298899eca2 net: change GetBindAddress() to take Sock argument (Vasil Dimov) 748dbcd9f29dbe4110da8a06f08e3eefa95f5321 net: add new method Sock::GetSockName() that wraps getsockname() (Vasil Dimov) Pull request description: _This is a piece of #21878, chopped off to ease review._ Wrap the syscall `getsockname()` in `Sock::GetSockName()` and change `GetBindAddress()` to take a `Sock` argument so that it can use the wrapper. This further encapsulates syscalls inside the `Sock` class and makes the callers mockable. ACKs for top commit: laanwj: Code review ACK a8d6abba5ec4ae2a3375e9be0b739f298899eca2 Tree-SHA512: 3a73463258c0057487fb3fd67215816b03a1c5160f45e45930eaeef86bb3611ec385794cdb08339aa074feba8ad67cd2bfd3836f6cbd40834e15d933214a05dc
Diffstat (limited to 'src/util/sock.h')
-rw-r--r--src/util/sock.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/util/sock.h b/src/util/sock.h
index 5ca5f1b91b..73ceb0b62c 100644
--- a/src/util/sock.h
+++ b/src/util/sock.h
@@ -114,6 +114,13 @@ public:
const void* opt_val,
socklen_t opt_len) const;
+ /**
+ * getsockname(2) wrapper. Equivalent to
+ * `getsockname(this->Get(), name, name_len)`. Code that uses this
+ * wrapper can be unit tested if this method is overridden by a mock Sock implementation.
+ */
+ [[nodiscard]] virtual int GetSockName(sockaddr* name, socklen_t* name_len) const;
+
using Event = uint8_t;
/**