Пример #1
0
 void start()
 {
     socket_.async_receive([this](boost::system::error_code const& ec,
                                  azmq::message & msg, size_t) {
             if (ec)
                 return;
             event_t event;
             msg.buffer_copy(boost::asio::buffer(&event, sizeof(event)));
             events_.push_back(event);
             socket_.flush();
             start();
         });
 }
Пример #2
0
void ChannelServer::nextMonitorEvent(StreamIdx idx, azmq::socket &socket) {
    auto self = shared_from_this();
    socket.async_receive([this, self, idx, &socket](
        const error_code &ec, azmq::message &msg, size_t) {
        if (ec == errc::operation_canceled) {
            // We are shutting down.
            return;
        }

        if (ec) {
            BOOST_LOG_TRIVIAL(error) << "Error receiving streaming monitor "
                                        "event; should not happen unless there "
                                        "is a ZeroMQ-internal problem?";
            nextMonitorEvent(idx, socket);
            return;
        }

        if (!msg.more()) {
            BOOST_LOG_TRIVIAL(error) << "Streaming monitor event only consists "
                                        "of one part; should not happen unless "
                                        "there is a ZeroMQ-internal problem?";
            nextMonitorEvent(idx, socket);
            return;
        }

        MonitorEvent event;
        msg.buffer_copy(buffer(&event, sizeof(event)));

        if (event.type == ZMQ_EVENT_ACCEPTED) {
            addStreamSubscription(idx);
        } else if (event.type == ZMQ_EVENT_DISCONNECTED) {
            removeStreamSubscription(idx);
        } else {
            // This might be triggered if the ZeroMQ API is changed in the
            // future. Have a look at the API docs to see if we need to handle
            // that event type then. Currently, all the other events should not
            // be triggered during normal operation of the server.
            BOOST_LOG_TRIVIAL(info)
                << "Ignoring streaming socket monitor event: type = "
                << event.type << ", value = " << event.value;
        }

        socket.flush();
        nextMonitorEvent(idx, socket);
    });
}