diff --git a/src/net/async_server.cpp b/src/net/async_server.cpp index 9499f2f9c0eda17fec63312c243642e75cdeb9f9..9ad38f83ff4d82d2eaa60c57a0ae4eaafbac6c53 100644 --- a/src/net/async_server.cpp +++ b/src/net/async_server.cpp @@ -12,7 +12,7 @@ namespace rmrf::net::asio { -async_server_socket::async_server_socket(auto_fd&& socket_fd) : socket(std::forward(socket_fd)) { +async_server_socket::async_server_socket(auto_fd&& socket_fd) : socket(std::forward(socket_fd)), on_accept{}, on_error{}, io{} { // This constructor got a constructed socket as an argument // and forwards it to libev io.set<async_server_socket, &async_server_socket::cb_ev>(this); @@ -43,5 +43,15 @@ void async_server_socket::cb_ev(::ev::io &w, int events) { } } +inline void async_server_socket::set_accept_handler( + const accept_handler_type &value) { + on_accept = value; +} + + +inline async_server_socket::accept_handler_type async_server_socket::get_accept_handler() const { + return on_accept; +} + } diff --git a/src/net/async_server.hpp b/src/net/async_server.hpp index a269d18805ee8686e5cfccac105e02ccca27e12c..abf03ea76f26fe3b75d0f912666ea100e68a2104 100644 --- a/src/net/async_server.hpp +++ b/src/net/async_server.hpp @@ -28,34 +28,14 @@ public: async_server_socket(auto_fd &&fd); ~async_server_socket(); -public: void cb_ev(::ev::io &w, int events); - accept_handler_type get_accept_handler() const { - return on_accept; - } - void set_accept_handler(const accept_handler_type &value) { - on_accept = value; - } + accept_handler_type get_accept_handler() const; + void set_accept_handler(const accept_handler_type &value); private: - void cb_ev(::ev::io &w, int events) - { - (void)w; - - if (events & ::ev::READ) { - auto ah = this->get_accept_handler(); - // Handle accepting clients - } - - if (events & ::ev::WRITE) { - // Handle sending data (none for servers) - } - - if (events & ::ev::ERROR) { - // Handle error conditions - } - } + void cb_ev(::ev::io &w, int events); }; + }