refactor: use std::mutex in net/TCPListenSocket

This commit is contained in:
sithlord48
2025-06-10 21:28:43 -04:00
committed by Nick Bolton
parent 818d588b65
commit 5686d24626
2 changed files with 5 additions and 8 deletions

View File

@ -12,8 +12,6 @@
#include "base/IEventQueue.h"
#include "base/Log.h"
#include "io/XIO.h"
#include "mt/Lock.h"
#include "mt/Mutex.h"
#include "net/NetworkAddress.h"
#include "net/SocketMultiplexer.h"
#include "net/TCPSocket.h"
@ -30,7 +28,6 @@ TCPListenSocket::TCPListenSocket(
: m_events(events),
m_socketMultiplexer(socketMultiplexer)
{
m_mutex = new Mutex;
try {
m_socket = ARCH->newSocket(family, IArchNetwork::kSTREAM);
} catch (XArchNetwork &e) {
@ -49,13 +46,12 @@ TCPListenSocket::~TCPListenSocket()
// ignore
LOG((CLOG_WARN "error while closing TCP socket"));
}
delete m_mutex;
}
void TCPListenSocket::bind(const NetworkAddress &addr)
{
try {
Lock lock(m_mutex);
std::lock_guard<std::mutex> lock(m_mutex);
ARCH->setReuseAddrOnSocket(m_socket, true);
ARCH->bindSocket(m_socket, addr.getAddress());
ARCH->listenOnSocket(m_socket);
@ -73,7 +69,7 @@ void TCPListenSocket::bind(const NetworkAddress &addr)
void TCPListenSocket::close()
{
Lock lock(m_mutex);
std::lock_guard<std::mutex> lock(m_mutex);
if (m_socket == nullptr) {
throw XIOClosed();
}

View File

@ -10,7 +10,8 @@
#include "arch/IArchNetwork.h"
#include "net/IListenSocket.h"
class Mutex;
#include <mutex>
class ISocketMultiplexerJob;
class IEventQueue;
class SocketMultiplexer;
@ -46,7 +47,7 @@ public:
protected:
ArchSocket m_socket;
Mutex *m_mutex = nullptr;
std::mutex m_mutex;
IEventQueue *m_events;
SocketMultiplexer *m_socketMultiplexer;
};