readable_stream(reactor_t& reactor, const std::shared_ptr<socket_type>& socket): m_socket(socket), m_socket_watcher(reactor.native()), m_idle_watcher(reactor.native()), m_reactor(reactor), m_rd_offset(0), m_rx_offset(0) { m_socket_watcher.set<readable_stream, &readable_stream::on_event>(this); m_idle_watcher.set<readable_stream, &readable_stream::on_idle>(this); m_ring.resize(65536); }
readable_stream(reactor_t& reactor, endpoint_type endpoint): m_socket(std::make_shared<socket_type>(endpoint)), m_socket_watcher(reactor.native()), m_idle_watcher(reactor.native()), m_reactor(reactor), m_rd_offset(0), m_rx_offset(0) { m_socket_watcher.set<readable_stream, &readable_stream::on_event>(this); m_idle_watcher.set<readable_stream, &readable_stream::on_idle>(this); m_ring.resize(65536); }
writable_stream(reactor_t& reactor, const std::shared_ptr<socket_type>& socket): m_socket(socket), m_socket_watcher(reactor.native()), m_tx_offset(0), m_wr_offset(0) { m_socket_watcher.set<writable_stream, &writable_stream::on_event>(this); m_ring.resize(65536); }
blastbeat_t::blastbeat_t(context_t& context, reactor_t& reactor, app_t& app, const std::string& name, const Json::Value& args): category_type(context, reactor, app, name, args), m_context(context), m_log(new log_t(context, cocaine::format("app/%s", name))), m_reactor(reactor), m_app(app), m_event(args.get("emit", "").asString()), m_endpoint(args.get("endpoint", "").asString()), m_zmq(1), m_socket(m_zmq, ZMQ_DEALER), m_watcher(reactor.native()), m_checker(reactor.native()) { try { m_socket.setsockopt( ZMQ_IDENTITY, m_context.config.network.hostname.data(), m_context.config.network.hostname.size() ); } catch(const zmq::error_t& e) { throw configuration_error_t("invalid driver identity - %s", e.what()); } int timeout = 0; size_t timeout_size = sizeof(timeout); m_socket.setsockopt(ZMQ_RCVTIMEO, &timeout, timeout_size); try { m_socket.connect(m_endpoint.c_str()); } catch(const zmq::error_t& e) { throw configuration_error_t("invalid driver endpoint - %s", e.what()); } int fd = 0; size_t fd_size = sizeof(fd); // Get the socket's file descriptor. m_socket.getsockopt(ZMQ_FD, &fd, &fd_size); m_watcher.set<blastbeat_t, &blastbeat_t::on_event>(this); m_watcher.start(fd, ev::READ); m_checker.set<blastbeat_t, &blastbeat_t::on_check>(this); m_checker.start(); }
fs_t::fs_t(context_t& context, reactor_t& reactor, app_t& app, const std::string& name, const Json::Value& args): category_type(context, reactor, app, name, args), m_context(context), m_log(new log_t(context, cocaine::format("app/%s", name))), m_app(app), m_event(args.get("emit", "").asString()), m_path(args.get("path", "").asString()), m_watcher(reactor.native()) { if(m_path.empty()) { throw configuration_error_t("no path has been specified"); } m_watcher.set<fs_t, &fs_t::on_event>(this); m_watcher.start(m_path.c_str()); }
dealer_t::dealer_t(context_t& context, reactor_t& reactor, app_t& app, const std::string& name, const Json::Value& args): category_type(context, reactor, app, name, args), m_context(context), m_log(new log_t(context, cocaine::format("app/%s", name))), m_reactor(reactor), m_app(app), m_event(args["emit"].asString()), m_identity( cocaine::format("%s/%s", m_context.config.network.hostname, name) ), m_channel(context, ZMQ_ROUTER, m_identity), m_watcher(reactor.native()), m_checker(reactor.native()) { std::string endpoint(args["endpoint"].asString()); try { if(endpoint.empty()) { m_channel.bind(); } else { m_channel.bind(endpoint); } } catch(const zmq::error_t& e) { throw configuration_error_t("invalid driver endpoint - %s", e.what()); } m_watcher.set<dealer_t, &dealer_t::on_event>(this); m_watcher.start(m_channel.fd(), ev::READ); m_checker.set<dealer_t, &dealer_t::on_check>(this); m_checker.start(); }