comparison irccdctl/cli.cpp @ 670:95ac3ace1610

Common: introduce new io code To avoid code duplication in accept, connect, reading and writing we add a new set of classes in `io` namespaces located in the following files: - stream.hpp, acceptor.hpp, connector.hpp These classes consist of pure abstract interfaces for I/O. Then we reimplement them in the following files: - socket_stream.hpp, socket_acceptor.hpp, socket_connector.hpp, - tls_stream.hpp, tls_acceptor.hpp, tls_conncetor.hpp (for SSL). This allows future independant connections such as DBus, fifo or any other fancy optional stuff. We also no longer need large class hierarchy such as `connection` for irccdctl controller or transport_server, transport_client classes.
author David Demelier <markand@malikania.fr>
date Tue, 10 Apr 2018 21:20:30 +0200
parents 4a13a016ea4f
children ad1ee47165fa
comparison
equal deleted inserted replaced
669:6eb4caea77a5 670:95ac3ace1610
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */ 17 */
18 18
19 #include <boost/system/system_error.hpp>
20
21 #include <irccd/json_util.hpp> 19 #include <irccd/json_util.hpp>
22 #include <irccd/options.hpp> 20 #include <irccd/options.hpp>
23 #include <irccd/string_util.hpp> 21 #include <irccd/string_util.hpp>
24 22
25 #include <irccd/ctl/controller.hpp> 23 #include <irccd/ctl/controller.hpp>
30 28
31 namespace ctl { 29 namespace ctl {
32 30
33 void cli::recv_response(ctl::controller& ctl, nlohmann::json req, handler_t handler) 31 void cli::recv_response(ctl::controller& ctl, nlohmann::json req, handler_t handler)
34 { 32 {
35 ctl.recv([&ctl, req, handler, this] (auto code, auto message) { 33 ctl.read([&ctl, req, handler, this] (auto code, auto message) {
36 if (code) 34 if (code)
37 throw boost::system::system_error(code); 35 throw std::system_error(code);
38 36
39 const auto c = json_util::parser(message).get<std::string>("command"); 37 const auto c = json_util::parser(message).get<std::string>("command");
40 38
41 if (!c) { 39 if (!c) {
42 recv_response(ctl, std::move(req), std::move(handler)); 40 recv_response(ctl, std::move(req), std::move(handler));
48 }); 46 });
49 } 47 }
50 48
51 void cli::request(ctl::controller& ctl, nlohmann::json req, handler_t handler) 49 void cli::request(ctl::controller& ctl, nlohmann::json req, handler_t handler)
52 { 50 {
53 ctl.send(req, [&ctl, req, handler, this] (auto code) { 51 ctl.write(req, [&ctl, req, handler, this] (auto code) {
54 if (code) 52 if (code)
55 throw boost::system::system_error(code); 53 throw std::system_error(code);
56 54
57 recv_response(ctl, std::move(req), std::move(handler)); 55 recv_response(ctl, std::move(req), std::move(handler));
58 }); 56 });
59 } 57 }
60 58