changeset 765:3f5e8ae58a84

Irccd: style (transport_client|transport_server)
author David Demelier <markand@malikania.fr>
date Mon, 13 Aug 2018 13:29:00 +0200
parents 46ec61c095c1
children 80e2d5284b4a
files libirccd/irccd/daemon/transport_client.cpp libirccd/irccd/daemon/transport_client.hpp libirccd/irccd/daemon/transport_server.cpp libirccd/irccd/daemon/transport_server.hpp libirccd/irccd/daemon/transport_service.cpp
diffstat 5 files changed, 65 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/libirccd/irccd/daemon/transport_client.cpp	Mon Aug 13 13:54:50 2018 +0200
+++ b/libirccd/irccd/daemon/transport_client.cpp	Mon Aug 13 13:29:00 2018 +0200
@@ -16,6 +16,8 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
+#include <cassert>
+
 #include "transport_client.hpp"
 #include "transport_server.hpp"
 
@@ -43,17 +45,34 @@
 
 void transport_client::erase()
 {
-    state_ = state_t::closing;
+    state_ = state::closing;
 
     if (auto parent = parent_.lock())
         parent->get_clients().erase(shared_from_this());
 }
 
+transport_client::transport_client(std::weak_ptr<transport_server> server, std::shared_ptr<io::stream> stream) noexcept
+    : parent_(server)
+    , stream_(std::move(stream))
+{
+    assert(stream_);
+}
+
+auto transport_client::get_state() const noexcept -> state
+{
+    return state_;
+}
+
+void transport_client::set_state(state state) noexcept
+{
+    state_ = state;
+}
+
 void transport_client::read(io::read_handler handler)
 {
     assert(handler);
 
-    if (state_ != state_t::closing) {
+    if (state_ != state::closing) {
         const auto self = shared_from_this();
 
         stream_->read([this, self, handler] (auto code, auto msg) {
@@ -110,7 +129,7 @@
             handler(code);
     });
 
-    state_ = state_t::closing;
+    state_ = state::closing;
 }
 
 } // !irccd
--- a/libirccd/irccd/daemon/transport_client.hpp	Mon Aug 13 13:54:50 2018 +0200
+++ b/libirccd/irccd/daemon/transport_client.hpp	Mon Aug 13 13:29:00 2018 +0200
@@ -19,7 +19,6 @@
 #ifndef IRCCD_DAEMON_TRANSPORT_CLIENT_HPP
 #define IRCCD_DAEMON_TRANSPORT_CLIENT_HPP
 
-#include <cassert>
 #include <deque>
 #include <memory>
 #include <string_view>
@@ -40,14 +39,14 @@
     /**
      * Client state.
      */
-    enum class state_t {
+    enum class state {
         authenticating,                     //!< client is authenticating
         ready,                              //!< client is ready
         closing                             //!< client is closing
     };
 
 private:
-    state_t state_{state_t::authenticating};
+    state state_{state::authenticating};
     std::weak_ptr<transport_server> parent_;
     std::shared_ptr<io::stream> stream_;
     std::deque<std::pair<nlohmann::json, io::write_handler>> queue_;
@@ -63,32 +62,21 @@
      * \param server the parent
      * \param stream the I/O stream
      */
-    inline transport_client(std::weak_ptr<transport_server> server, std::shared_ptr<io::stream> stream) noexcept
-        : parent_(server)
-        , stream_(std::move(stream))
-    {
-        assert(stream_);
-    }
+    transport_client(std::weak_ptr<transport_server> server, std::shared_ptr<io::stream> stream) noexcept;
 
     /**
      * Get the current client state.
      *
      * \return the state
      */
-    inline state_t get_state() const noexcept
-    {
-        return state_;
-    }
+    auto get_state() const noexcept -> state;
 
     /**
      * Set the client state.
      *
      * \param state the new state
      */
-    inline void set_state(state_t state) noexcept
-    {
-        state_ = state;
-    }
+    void set_state(state state) noexcept;
 
     /**
      * Start receiving if not closed.
--- a/libirccd/irccd/daemon/transport_server.cpp	Mon Aug 13 13:54:50 2018 +0200
+++ b/libirccd/irccd/daemon/transport_server.cpp	Mon Aug 13 13:29:00 2018 +0200
@@ -52,7 +52,7 @@
             code = irccd_error::invalid_auth;
         } else {
             clients_.insert(client);
-            client->set_state(transport_client::state_t::ready);
+            client->set_state(transport_client::state::ready);
             client->success("auth");
             code = irccd_error::no_error;
         }
@@ -89,12 +89,38 @@
             do_auth(std::move(client), std::move(handler));
         else {
             clients_.insert(client);
-            client->set_state(transport_client::state_t::ready);
+            client->set_state(transport_client::state::ready);
             handler(std::move(code), std::move(client));
         }
     });
 }
 
+transport_server::transport_server(std::unique_ptr<io::acceptor> acceptor) noexcept
+    : acceptor_(std::move(acceptor))
+{
+    assert(acceptor_);
+}
+
+auto transport_server::get_clients() const noexcept -> const client_set&
+{
+    return clients_;
+}
+
+auto transport_server::get_clients() noexcept -> client_set&
+{
+    return clients_;
+}
+
+auto transport_server::get_password() const noexcept -> const std::string&
+{
+    return password_;
+}
+
+void transport_server::set_password(std::string password) noexcept
+{
+    password_ = std::move(password);
+}
+
 void transport_server::accept(accept_handler handler)
 {
     acceptor_->accept([this, handler] (auto code, auto stream) {
@@ -115,7 +141,7 @@
 {
 }
 
-const std::error_category& transport_category() noexcept
+auto transport_category() noexcept -> const std::error_category&
 {
     static const class category : public std::error_category {
     public:
@@ -158,7 +184,7 @@
     return category;
 };
 
-std::error_code make_error_code(transport_error::error e) noexcept
+auto make_error_code(transport_error::error e) noexcept -> std::error_code
 {
     return {static_cast<int>(e), transport_category()};
 }
--- a/libirccd/irccd/daemon/transport_server.hpp	Mon Aug 13 13:54:50 2018 +0200
+++ b/libirccd/irccd/daemon/transport_server.hpp	Mon Aug 13 13:29:00 2018 +0200
@@ -26,7 +26,6 @@
 
 #include <irccd/sysconfig.hpp>
 
-#include <cassert>
 #include <functional>
 #include <memory>
 #include <unordered_set>
@@ -154,51 +153,35 @@
      * \pre acceptor != nullptr
      * \param acceptor the stream acceptor
      */
-    inline transport_server(std::unique_ptr<io::acceptor> acceptor) noexcept
-        : acceptor_(std::move(acceptor))
-    {
-        assert(acceptor_);
-    }
+    transport_server(std::unique_ptr<io::acceptor> acceptor) noexcept;
 
     /**
      * Get the clients.
      *
      * \return the clients
      */
-    inline const client_set& get_clients() const noexcept
-    {
-        return clients_;
-    }
+    auto get_clients() const noexcept -> const client_set&;
 
     /**
      * Overloaded function.
      *
      * \return the clients
      */
-    inline client_set& get_clients() noexcept
-    {
-        return clients_;
-    }
+    auto get_clients() noexcept -> client_set&;
 
     /**
      * Get the current password, empty string means no password.
      *
      * \return the password
      */
-    inline const std::string& get_password() const noexcept
-    {
-        return password_;
-    }
+    auto get_password() const noexcept -> const std::string&;
 
     /**
      * Set an optional password, empty string means no password.
      *
      * \param password the password
      */
-    inline void set_password(std::string password) noexcept
-    {
-        password_ = std::move(password);
-    }
+    void set_password(std::string password) noexcept;
 
     /**
      * Accept a client.
@@ -271,14 +254,14 @@
  *
  * \return the singleton
  */
-const std::error_category& transport_category() noexcept;
+auto transport_category() noexcept -> const std::error_category&;
 
 /**
  * Create a std::error_code from server_error::error enum.
  *
  * \param e the error code
  */
-std::error_code make_error_code(transport_error::error e) noexcept;
+auto make_error_code(transport_error::error e) noexcept -> std::error_code;
 
 } // !irccd
 
--- a/libirccd/irccd/daemon/transport_service.cpp	Mon Aug 13 13:54:50 2018 +0200
+++ b/libirccd/irccd/daemon/transport_service.cpp	Mon Aug 13 13:29:00 2018 +0200
@@ -78,7 +78,7 @@
             if (!code) {
                 handle_command(tc, json);
 
-                if (tc->get_state() == transport_client::state_t::ready)
+                if (tc->get_state() == transport_client::state::ready)
                     do_recv(std::move(tc));
             }