aboutsummaryrefslogtreecommitdiff
path: root/src/util/sock.cpp
diff options
context:
space:
mode:
authorVasil Dimov <vd@FreeBSD.org>2022-06-21 15:23:37 +0200
committerVasil Dimov <vd@FreeBSD.org>2022-06-22 09:19:43 +0200
commita724c39606273dfe4c6f9887ef8b77d0a98f1b34 (patch)
tree092db93c07cbfce5dd25cc5353a342197390a619 /src/util/sock.cpp
parente8ff3f0c52e7512a580bc907dc72e5bb141b4217 (diff)
net: rename Sock::Reset() to Sock::Close() and make it private
Outside of `Sock`, `Sock::Reset()` was used in just one place (in `i2p.cpp`) which can use the assignment operator instead. This simplifies the public `Sock` API by having one method less.
Diffstat (limited to 'src/util/sock.cpp')
-rw-r--r--src/util/sock.cpp35
1 files changed, 18 insertions, 17 deletions
diff --git a/src/util/sock.cpp b/src/util/sock.cpp
index aca83d4170..1d44fbfdae 100644
--- a/src/util/sock.cpp
+++ b/src/util/sock.cpp
@@ -39,11 +39,11 @@ Sock::Sock(Sock&& other)
other.m_socket = INVALID_SOCKET;
}
-Sock::~Sock() { Reset(); }
+Sock::~Sock() { Close(); }
Sock& Sock::operator=(Sock&& other)
{
- Reset();
+ Close();
m_socket = other.m_socket;
other.m_socket = INVALID_SOCKET;
return *this;
@@ -51,21 +51,6 @@ Sock& Sock::operator=(Sock&& other)
SOCKET Sock::Get() const { return m_socket; }
-void Sock::Reset() {
- if (m_socket == INVALID_SOCKET) {
- return;
- }
-#ifdef WIN32
- int ret = closesocket(m_socket);
-#else
- int ret = close(m_socket);
-#endif
- if (ret) {
- LogPrintf("Error closing socket %d: %s\n", m_socket, NetworkErrorString(WSAGetLastError()));
- }
- m_socket = INVALID_SOCKET;
-}
-
ssize_t Sock::Send(const void* data, size_t len, int flags) const
{
return send(m_socket, static_cast<const char*>(data), len, flags);
@@ -372,6 +357,22 @@ bool Sock::IsConnected(std::string& errmsg) const
}
}
+void Sock::Close()
+{
+ if (m_socket == INVALID_SOCKET) {
+ return;
+ }
+#ifdef WIN32
+ int ret = closesocket(m_socket);
+#else
+ int ret = close(m_socket);
+#endif
+ if (ret) {
+ LogPrintf("Error closing socket %d: %s\n", m_socket, NetworkErrorString(WSAGetLastError()));
+ }
+ m_socket = INVALID_SOCKET;
+}
+
#ifdef WIN32
std::string NetworkErrorString(int err)
{