event/ServerSocket: add `noexcept`

This commit is contained in:
Max Kellermann 2018-10-30 19:57:39 +01:00
parent f5857c4689
commit 5fb21fbdb1
2 changed files with 19 additions and 19 deletions

View File

@ -67,7 +67,7 @@ public:
template<typename A> template<typename A>
OneServerSocket(EventLoop &_loop, ServerSocket &_parent, OneServerSocket(EventLoop &_loop, ServerSocket &_parent,
unsigned _serial, unsigned _serial,
A &&_address) A &&_address) noexcept
:SocketMonitor(_loop), :SocketMonitor(_loop),
parent(_parent), serial(_serial), parent(_parent), serial(_serial),
#ifdef HAVE_UN #ifdef HAVE_UN
@ -80,17 +80,17 @@ public:
OneServerSocket(const OneServerSocket &other) = delete; OneServerSocket(const OneServerSocket &other) = delete;
OneServerSocket &operator=(const OneServerSocket &other) = delete; OneServerSocket &operator=(const OneServerSocket &other) = delete;
~OneServerSocket() { ~OneServerSocket() noexcept {
if (IsDefined()) if (IsDefined())
Close(); Close();
} }
unsigned GetSerial() const { unsigned GetSerial() const noexcept {
return serial; return serial;
} }
#ifdef HAVE_UN #ifdef HAVE_UN
void SetPath(AllocatedPath &&_path) { void SetPath(AllocatedPath &&_path) noexcept {
assert(path.IsNull()); assert(path.IsNull());
path = std::move(_path); path = std::move(_path);
@ -197,12 +197,12 @@ OneServerSocket::Open()
SetFD(_fd.Release()); SetFD(_fd.Release());
} }
ServerSocket::ServerSocket(EventLoop &_loop) ServerSocket::ServerSocket(EventLoop &_loop) noexcept
:loop(_loop), next_serial(1) {} :loop(_loop), next_serial(1) {}
/* this is just here to allow the OneServerSocket forward /* this is just here to allow the OneServerSocket forward
declaration */ declaration */
ServerSocket::~ServerSocket() {} ServerSocket::~ServerSocket() noexcept = default;
void void
ServerSocket::Open() ServerSocket::Open()
@ -265,7 +265,7 @@ ServerSocket::Open()
} }
void void
ServerSocket::Close() ServerSocket::Close() noexcept
{ {
for (auto &i : sockets) for (auto &i : sockets)
if (i.IsDefined()) if (i.IsDefined())
@ -273,7 +273,7 @@ ServerSocket::Close()
} }
OneServerSocket & OneServerSocket &
ServerSocket::AddAddress(SocketAddress address) ServerSocket::AddAddress(SocketAddress address) noexcept
{ {
sockets.emplace_back(loop, *this, next_serial, sockets.emplace_back(loop, *this, next_serial,
address); address);
@ -282,7 +282,7 @@ ServerSocket::AddAddress(SocketAddress address)
} }
OneServerSocket & OneServerSocket &
ServerSocket::AddAddress(AllocatedSocketAddress &&address) ServerSocket::AddAddress(AllocatedSocketAddress &&address) noexcept
{ {
sockets.emplace_back(loop, *this, next_serial, sockets.emplace_back(loop, *this, next_serial,
std::move(address)); std::move(address));
@ -308,7 +308,7 @@ ServerSocket::AddFD(int _fd)
#ifdef HAVE_TCP #ifdef HAVE_TCP
inline void inline void
ServerSocket::AddPortIPv4(unsigned port) ServerSocket::AddPortIPv4(unsigned port) noexcept
{ {
AddAddress(IPv4Address(port)); AddAddress(IPv4Address(port));
} }
@ -316,7 +316,7 @@ ServerSocket::AddPortIPv4(unsigned port)
#ifdef HAVE_IPV6 #ifdef HAVE_IPV6
inline void inline void
ServerSocket::AddPortIPv6(unsigned port) ServerSocket::AddPortIPv6(unsigned port) noexcept
{ {
struct sockaddr_in6 sin; struct sockaddr_in6 sin;
memset(&sin, 0, sizeof(sin)); memset(&sin, 0, sizeof(sin));

View File

@ -42,30 +42,30 @@ class ServerSocket {
unsigned next_serial; unsigned next_serial;
public: public:
ServerSocket(EventLoop &_loop); ServerSocket(EventLoop &_loop) noexcept;
~ServerSocket(); ~ServerSocket() noexcept;
EventLoop &GetEventLoop() { EventLoop &GetEventLoop() const noexcept {
return loop; return loop;
} }
private: private:
OneServerSocket &AddAddress(SocketAddress address); OneServerSocket &AddAddress(SocketAddress address) noexcept;
OneServerSocket &AddAddress(AllocatedSocketAddress &&address); OneServerSocket &AddAddress(AllocatedSocketAddress &&address) noexcept;
/** /**
* Add a listener on a port on all IPv4 interfaces. * Add a listener on a port on all IPv4 interfaces.
* *
* @param port the TCP port * @param port the TCP port
*/ */
void AddPortIPv4(unsigned port); void AddPortIPv4(unsigned port) noexcept;
/** /**
* Add a listener on a port on all IPv6 interfaces. * Add a listener on a port on all IPv6 interfaces.
* *
* @param port the TCP port * @param port the TCP port
*/ */
void AddPortIPv6(unsigned port); void AddPortIPv6(unsigned port) noexcept;
public: public:
/** /**
@ -118,7 +118,7 @@ public:
*/ */
void Open(); void Open();
void Close(); void Close() noexcept;
protected: protected:
virtual void OnAccept(UniqueSocketDescriptor fd, virtual void OnAccept(UniqueSocketDescriptor fd,