aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorVasil Dimov <vd@FreeBSD.org>2021-04-13 16:43:04 +0200
committerVasil Dimov <vd@FreeBSD.org>2022-05-18 16:40:13 +0200
commitb2733ab6a85b234a88b83bdc77a0d043e18385b3 (patch)
tree89ebd1d42740c4923a7682b852668078136574dd /src/util
parent3ad7de225efce3e76530f56bee8a8f7a75ea0f3c (diff)
net: add new method Sock::Listen() that wraps listen()
This will help to increase `Sock` usage and make more code mockable.
Diffstat (limited to 'src/util')
-rw-r--r--src/util/sock.cpp5
-rw-r--r--src/util/sock.h6
2 files changed, 11 insertions, 0 deletions
diff --git a/src/util/sock.cpp b/src/util/sock.cpp
index 89d7a1a7ec..6097c29170 100644
--- a/src/util/sock.cpp
+++ b/src/util/sock.cpp
@@ -79,6 +79,11 @@ int Sock::Bind(const sockaddr* addr, socklen_t addr_len) const
return bind(m_socket, addr, addr_len);
}
+int Sock::Listen(int backlog) const
+{
+ return listen(m_socket, backlog);
+}
+
std::unique_ptr<Sock> Sock::Accept(sockaddr* addr, socklen_t* addr_len) const
{
#ifdef WIN32
diff --git a/src/util/sock.h b/src/util/sock.h
index 6a7840f4e2..6835757328 100644
--- a/src/util/sock.h
+++ b/src/util/sock.h
@@ -104,6 +104,12 @@ public:
[[nodiscard]] virtual int Bind(const sockaddr* addr, socklen_t addr_len) const;
/**
+ * listen(2) wrapper. Equivalent to `listen(this->Get(), backlog)`. Code that uses this
+ * wrapper can be unit tested if this method is overridden by a mock Sock implementation.
+ */
+ [[nodiscard]] virtual int Listen(int backlog) const;
+
+ /**
* accept(2) wrapper. Equivalent to `std::make_unique<Sock>(accept(this->Get(), addr, addr_len))`.
* Code that uses this wrapper can be unit tested if this method is overridden by a mock Sock
* implementation.