Merge pull request #2 from lioncash/noexcept

Socket: Mark interface noexcept where applicable
This commit is contained in:
Phillip Stephens 2019-08-22 18:35:49 -07:00 committed by GitHub
commit 876c4dcde4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 23 deletions

View File

@ -21,13 +21,13 @@ class IPAddress {
uint32_t m_address = 0; uint32_t m_address = 0;
bool m_valid = false; bool m_valid = false;
void resolve(const std::string& address); void resolve(const std::string& address) noexcept;
public: public:
explicit IPAddress(const std::string& address) { resolve(address); } explicit IPAddress(const std::string& address) noexcept { resolve(address); }
uint32_t toInteger() const; uint32_t toInteger() const noexcept;
explicit operator bool() const { return m_valid; } explicit operator bool() const noexcept { return m_valid; }
}; };
/** Server-oriented TCP socket class derived from SFML */ /** Server-oriented TCP socket class derived from SFML */
@ -40,23 +40,23 @@ class Socket {
SocketTp m_socket = -1; SocketTp m_socket = -1;
bool m_isBlocking; bool m_isBlocking;
bool openSocket(); bool openSocket() noexcept;
void setRemoteSocket(int remSocket); void setRemoteSocket(int remSocket) noexcept;
public: public:
enum class EResult { OK, Error, Busy }; enum class EResult { OK, Error, Busy };
#ifdef _WIN32 #ifdef _WIN32
static EResult LastWSAError(); static EResult LastWSAError() noexcept;
#endif #endif
explicit Socket(bool blocking) : m_isBlocking(blocking) {} explicit Socket(bool blocking) noexcept : m_isBlocking(blocking) {}
~Socket() { close(); } ~Socket() noexcept { close(); }
Socket(const Socket& other) = delete; Socket(const Socket& other) = delete;
Socket& operator=(const Socket& other) = delete; Socket& operator=(const Socket& other) = delete;
Socket(Socket&& other) : m_socket(other.m_socket), m_isBlocking(other.m_isBlocking) { other.m_socket = -1; } Socket(Socket&& other) noexcept : m_socket(other.m_socket), m_isBlocking(other.m_isBlocking) { other.m_socket = -1; }
Socket& operator=(Socket&& other) { Socket& operator=(Socket&& other) noexcept {
close(); close();
m_socket = other.m_socket; m_socket = other.m_socket;
other.m_socket = -1; other.m_socket = -1;
@ -64,21 +64,21 @@ public:
return *this; return *this;
} }
void setBlocking(bool blocking); void setBlocking(bool blocking) noexcept;
bool isOpen() const { return m_socket != -1; } bool isOpen() const noexcept { return m_socket != -1; }
bool openAndListen(const IPAddress& address, uint32_t port); bool openAndListen(const IPAddress& address, uint32_t port) noexcept;
EResult accept(Socket& remoteSocketOut, sockaddr_in& fromAddress); EResult accept(Socket& remoteSocketOut, sockaddr_in& fromAddress) noexcept;
EResult accept(Socket& remoteSocketOut); EResult accept(Socket& remoteSocketOut) noexcept;
EResult accept(Socket& remoteSocketOut, std::string& fromHostname); EResult accept(Socket& remoteSocketOut, std::string& fromHostname);
void close(); void close() noexcept;
EResult send(const void* buf, size_t len, size_t& transferred); EResult send(const void* buf, size_t len, size_t& transferred) noexcept;
EResult send(const void* buf, size_t len); EResult send(const void* buf, size_t len) noexcept;
EResult recv(void* buf, size_t len, size_t& transferred); EResult recv(void* buf, size_t len, size_t& transferred) noexcept;
EResult recv(void* buf, size_t len); EResult recv(void* buf, size_t len) noexcept;
explicit operator bool() const { return isOpen(); } explicit operator bool() const noexcept { return isOpen(); }
SocketTp GetInternalSocket() const { return m_socket; } SocketTp GetInternalSocket() const noexcept { return m_socket; }
}; };
} // namespace jbus::net } // namespace jbus::net