Mercurial > code
changeset 390:d7e6d7d1e102
Socket: get rid of SocketState
author | David Demelier <markand@malikania.fr> |
---|---|
date | Fri, 03 Jul 2015 13:02:05 +0200 |
parents | e292f0fa5395 |
children | e2cefd0ee511 |
files | C++/modules/Socket/Socket.cpp C++/modules/Socket/Socket.h C++/modules/Socket/SocketSsl.h C++/tests/Socket/main.cpp |
diffstat | 4 files changed, 2 insertions(+), 54 deletions(-) [+] |
line wrap: on
line diff
--- a/C++/modules/Socket/Socket.cpp Tue Jun 30 15:17:01 2015 +0200 +++ b/C++/modules/Socket/Socket.cpp Fri Jul 03 13:02:05 2015 +0200 @@ -26,7 +26,7 @@ * -------------------------------------------------------- */ #if defined(_WIN32) -const Socket::Handle SocketAbstract::Invalid{INVALID_SOCKET}; +const SocketAbstract::Handle SocketAbstract::Invalid{INVALID_SOCKET}; const int SocketAbstract::Error{SOCKET_ERROR}; #else const int SocketAbstract::Invalid{-1}; @@ -121,18 +121,14 @@ if (m_handle == Invalid) { throw SocketError{SocketError::System, "socket"}; } - - m_state = SocketState::Opened; } SocketAbstract::SocketAbstract(SocketAbstract &&other) noexcept { m_handle = other.m_handle; - m_state = other.m_state; // Invalidate other other.m_handle = -1; - other.m_state = SocketState::Closed; } SocketAbstract::~SocketAbstract() @@ -142,14 +138,13 @@ void SocketAbstract::close() { - if (m_state != SocketState::Closed) { + if (m_handle != Invalid) { #if defined(_WIN32) ::closesocket(m_handle); #else ::close(m_handle); #endif m_handle = Invalid; - m_state = SocketState::Closed; } } @@ -183,11 +178,9 @@ SocketAbstract &SocketAbstract::operator=(SocketAbstract &&other) noexcept { m_handle = other.m_handle; - m_state = other.m_state; // Invalidate other other.m_handle = Invalid; - other.m_state = SocketState::Closed; return *this; }
--- a/C++/modules/Socket/Socket.h Tue Jun 30 15:17:01 2015 +0200 +++ b/C++/modules/Socket/Socket.h Fri Jul 03 13:02:05 2015 +0200 @@ -146,19 +146,6 @@ } }; -/** - * @enum SocketState - * @brief Category of error - */ -enum class SocketState { - Opened, //!< Socket is opened - Closed, //!< Socket has been closed - Bound, //!< Socket is bound to address - Connected, //!< Socket is connected to an end point - Disconnected, //!< Socket is disconnected - Timeout //!< Timeout has occured in a waiting operation -}; - /* -------------------------------------------------------- * Generic base sockets * -------------------------------------------------------- */ @@ -299,7 +286,6 @@ protected: Handle m_handle{Invalid}; //!< The native handle - SocketState m_state{SocketState::Opened}; //!< The socket state public: /** @@ -323,7 +309,6 @@ */ inline SocketAbstract() noexcept : m_handle{Invalid} - , m_state{SocketState::Closed} { } @@ -334,7 +319,6 @@ */ explicit inline SocketAbstract(Handle handle) noexcept : m_handle{handle} - , m_state{SocketState::Opened} { } @@ -421,16 +405,6 @@ } /** - * Get the socket state. - * - * @return - */ - inline SocketState state() const noexcept - { - return m_state; - } - - /** * Set the blocking mode, if set to false, the socket will be marked * **non-blocking**. * @@ -499,8 +473,6 @@ if (::bind(m_handle, reinterpret_cast<const sockaddr *>(&sa), addrlen) == Error) { throw SocketError{SocketError::System, "bind"}; } - - m_state = SocketState::Bound; } /** @@ -676,10 +648,6 @@ template <typename Address> void SocketAbstractTcp<Address>::standardConnect(const Address &address) { - if (SocketAbstract::m_state == SocketState::Connected) { - return; - } - auto &sa = address.address(); auto addrlen = address.length(); @@ -704,8 +672,6 @@ throw SocketError{SocketError::System, "connect"}; #endif } - - SocketAbstract::m_state = SocketState::Connected; } /** @@ -803,8 +769,6 @@ throw SocketError{SocketError::System, "recv"}; #endif - } else if (nbread == 0) { - SocketAbstract::m_state = SocketState::Closed; } return static_cast<unsigned>(nbread);
--- a/C++/modules/Socket/SocketSsl.h Tue Jun 30 15:17:01 2015 +0200 +++ b/C++/modules/Socket/SocketSsl.h Fri Jul 03 13:02:05 2015 +0200 @@ -220,7 +220,6 @@ // Invalid other sc.m_handle = -1; - sc.m_state = SocketState::Closed; } template <typename Address> @@ -262,8 +261,6 @@ throw SocketError{SocketError::System, "connect", detail::error(error)}; } } - - SocketAbstract::m_state = SocketState::Connected; } template <typename Address>
--- a/C++/tests/Socket/main.cpp Tue Jun 30 15:17:01 2015 +0200 +++ b/C++/tests/Socket/main.cpp Fri Jul 03 13:02:05 2015 +0200 @@ -63,9 +63,6 @@ { m_tserver = std::thread([this] () { m_server.bind(Ipv4{"*", 16000}); - - ASSERT_EQ(SocketState::Bound, m_server.state()); - m_server.listen(); m_server.accept(); m_server.close(); @@ -75,9 +72,6 @@ m_tclient = std::thread([this] () { m_client.connect(Ipv4{"127.0.0.1", 16000}); - - ASSERT_EQ(SocketState::Connected, m_client.state()); - m_client.close(); }); }