Mercurial > code
diff C++/SocketListener.h @ 277:b544a599e08e
Socket: remove enum class
author | David Demelier <markand@malikania.fr> |
---|---|
date | Thu, 23 Oct 2014 17:59:14 +0200 |
parents | f7000cc599d0 |
children | adcae2bde2f0 |
line wrap: on
line diff
--- a/C++/SocketListener.h Thu Oct 23 17:08:13 2014 +0200 +++ b/C++/SocketListener.h Thu Oct 23 17:59:14 2014 +0200 @@ -39,52 +39,11 @@ * * Bitmask that can be set to both reading and writing. */ -enum class SocketDirection { +enum SocketDirection { Read = (1 << 0), //!< only for receive Write = (1 << 1) //!< only for sending }; -inline SocketDirection operator&(SocketDirection x, SocketDirection y) -{ - return static_cast<SocketDirection>(static_cast<int>(x) & static_cast<int>(y)); -} - -inline SocketDirection operator|(SocketDirection x, SocketDirection y) -{ - return static_cast<SocketDirection>(static_cast<int>(x) | static_cast<int>(y)); -} - -inline SocketDirection operator^(SocketDirection x, SocketDirection y) -{ - return static_cast<SocketDirection>(static_cast<int>(x) ^ static_cast<int>(y)); -} - -inline SocketDirection operator~(SocketDirection x) -{ - return static_cast<SocketDirection>(~static_cast<int>(x)); -} - -inline SocketDirection &operator&=(SocketDirection &x, SocketDirection y) -{ - x = x & y; - - return x; -} - -inline SocketDirection &operator|=(SocketDirection &x, SocketDirection y) -{ - x = x | y; - - return x; -} - -inline SocketDirection &operator^=(SocketDirection &x, SocketDirection y) -{ - x = x ^ y; - - return x; -} - /** * @enum SocketMethod * @brief The SocketMethod enum @@ -92,7 +51,7 @@ * Select the method of polling. It is only a preferred method, for example if you * request for poll but it is not available, select will be used. */ -enum class SocketMethod { +enum SocketMethod { Select, //!< select(2) method, fallback Poll //!< poll(2), everywhere possible }; @@ -105,8 +64,8 @@ * direction. */ struct SocketStatus { - Socket socket; //!< which socket is ready - SocketDirection direction; //!< the direction + Socket socket; //!< which socket is ready + int direction; //!< the direction }; /** @@ -120,7 +79,7 @@ /** * @brief Function for listing all sockets */ - using MapFunc = std::function<void (Socket &, SocketDirection)>; + using MapFunc = std::function<void (Socket &, int)>; #if defined(SOCKET_LISTENER_HAVE_POLL) static constexpr const SocketMethod PreferredMethod = SocketMethod::Poll; @@ -152,7 +111,7 @@ * @param s the socket * @param direction the direction */ - virtual void add(Socket &&s, SocketDirection direction) = 0; + virtual void add(Socket s, int direction) = 0; /** * Remove a socket with a specified direction. @@ -160,7 +119,7 @@ * @param s the socket * @param direction the direction */ - virtual void remove(const Socket &s, SocketDirection direction) = 0; + virtual void remove(const Socket &s, int direction) = 0; /** * Remove all sockets. @@ -216,7 +175,7 @@ * * @param method the preferred method */ - SocketListener(SocketMethod method = SocketMethod::Poll); + SocketListener(int method = Poll); /** * Add a socket to listen to. @@ -224,7 +183,7 @@ * @param s the socket * @param direction the direction */ - inline void add(Socket s, SocketDirection direction) + inline void add(Socket s, int direction) { m_interface->add(std::move(s), direction); } @@ -235,7 +194,7 @@ * @param s the socket * @param direction the direction */ - inline void remove(const Socket &s, SocketDirection direction) + inline void remove(const Socket &s, int direction) { m_interface->remove(s, direction); }