久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

將 ZeroMQ 與 Boost::ASIO 一起使用

Using ZeroMQ together with Boost::ASIO(將 ZeroMQ 與 Boost::ASIO 一起使用)
本文介紹了將 ZeroMQ 與 Boost::ASIO 一起使用的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有一個使用 ZeroMQ 進行消息傳遞的 C++ 應用程序.但它還必須為基于 AJAX/Comet 的 Web 服務提供 SGCI 連接.

I've got a C++ application that is using ZeroMQ for some messaging. But it also has to provide a SGCI connection for an AJAX / Comet based web service.

為此,我需要一個普通的 TCP 套接字.我可以通過普通的 Posix 套接字做到這一點,但為了保持跨平臺的便攜性并使我的生活更輕松(我希望......)我正在考慮使用 Boost::ASIO.

For this I need a normal TCP socket. I could do that by normal Posix sockets, but to stay cross platform portable and make my life easier (I hope...) I was thinking of using Boost::ASIO.

但現在我有 ZMQ 的沖突,想要使用它自己的 zmq_poll() 和 ASIO 它是 io_service.run()...

But now I have the clash of ZMQ wanting to use it's own zmq_poll() and ASIO it's io_service.run()...

有沒有辦法讓 ASIO 與 0MQ zmq_poll() 一起工作?

Is there a way to get ASIO to work together with the 0MQ zmq_poll()?

或者是否有其他推薦的方法來實現這樣的設置?

Or is there an other recommended way to achieve such a setup?

注意:我可以通過使用多線程來解決這個問題——但它只是一個小小的單核/CPU 盒子,它可以以非常低的 SCGI 流量運行該程序,所以多線程會浪費資源......

Note: I could solve that by using multiple threads - but it's only a little single core / CPU box that'll run that program with a very low amount of SCGI traffic, so multithreading would be a waste of resources...

推薦答案

閱讀文檔后 這里和這里,特別是這一段

After reading the documentation here and here, specifically this paragraph

ZMQ_FD:檢索與套接字關聯的文件描述符 ZMQ_FD選項應檢索與關聯的文件描述符指定的套接字.返回的文件描述符可用于將套接字集成到現有的事件循環中;?MQ 庫應以邊緣觸發的方式向套接字上的任何未決事件發出信號通過使文件描述符準備好讀取來實現時尚.

ZMQ_FD: Retrieve file descriptor associated with the socket The ZMQ_FD option shall retrieve the file descriptor associated with the specified socket. The returned file descriptor can be used to integrate the socket into an existing event loop; the ?MQ library shall signal any pending events on the socket in an edge-triggered fashion by making the file descriptor become ready for reading.

我認為您可以為每個 zmq_pollitem_t 使用 null_buffers并將事件循環推遲到 io_service,完全繞過 zmq_poll().然而,上述文檔中似乎有一些警告,特別是

I think you can use null_buffers for every zmq_pollitem_t and defer the event loop to an io_service, completely bypassing zmq_poll() altogether. There appear to be some caveats in the aforementioned documentation however, notably

從返回的文件描述符中讀取的能力不必然表明消息可供讀取,或可以寫入,底層套接字;應用程序必須檢索實際事件狀態,隨后檢索 ZMQ_EVENTS選項.

The ability to read from the returned file descriptor does not necessarily indicate that messages are available to be read from, or can be written to, the underlying socket; applications must retrieve the actual event state with a subsequent retrieval of the ZMQ_EVENTS option.

因此,當您的一個 zmq 套接字的處理程序被觸發時,您必須在處理我認為的事件之前做更多的工作.未編譯的偽代碼如下

So when the handler for one of your zmq sockets is fired, you'll have to do a little more work before handling the event I think. Uncompiled pseudo-code is below

const int fd = getZmqDescriptorSomehow();
boost::asio::posix::stream_descriptor socket( _io_service, fd );
socket->async_read_some(
    boost::asio::null_buffers(),
    [=](const boost::system::error_code& error)
    {
       if (!error) {
           // handle data ready to be read
       }
     }
);

注意你不必在這里使用 lambda,boost::bind 到成員函數就足夠了.

note you don't have to use a lambda here, boost::bind to a member function would be sufficient.

這篇關于將 ZeroMQ 與 Boost::ASIO 一起使用的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Assertion failed (size.widthgt;0 amp;amp; size.heightgt;0)(斷言失敗(size.width0 amp;amp; size.height0))
Rotate an image in C++ without using OpenCV functions(在 C++ 中旋轉圖像而不使用 OpenCV 函數)
OpenCV: process every frame(OpenCV:處理每一幀)
Why can#39;t I open avi video in openCV?(為什么我不能在 openCV 中打開 avi 視頻?)
OpenCV unable to set up SVM Parameters(OpenCV 無法設置 SVM 參數)
Convert a single color with cvtColor(使用 cvtColor 轉換單一顏色)
主站蜘蛛池模板: 国产精品一区二区免费 | 国产精品亚洲视频 | 亚洲免费高清 | 精品一区二区三区在线视频 | 亚洲人人| 狠狠久| 久久久综合精品 | 毛片a区| 久久久久久国产 | 亚洲欧美一区二区三区在线 | 在线观看中文视频 | 国产精品一区二区不卡 | 欧美精品一区二区免费视频 | 成人一区二 | 麻豆久久久 | 欧美成人猛片aaaaaaa | 天堂一区二区三区 | 欧美一区免费在线观看 | 伊人狠狠干 | 亚洲精品18 | 日本不卡免费新一二三区 | 伊人一区 | 女人一区 | 欧美成人第一页 | 福利视频三区 | 国产精品免费一区二区 | 免费看黄色视屏 | 久久av一区二区三区 | 久久午夜视频 | 日本中出视频 | 在线免费观看毛片 | 逼逼视频| 久久久久久久久久久久一区二区 | 久久久国产视频 | 九九热精品视频在线观看 | 欧美成人精品一区二区男人看 | 亚洲国产视频一区 | 一区二区精品 | 国产精品一区二区免费 | 欧美一级久久久猛烈a大片 日韩av免费在线观看 | 黄色一级大片在线观看 |