久久久久久久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.

但現(xiàn)在我有 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()?

或者是否有其他推薦的方法來實現(xiàn)這樣的設(shè)置?

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:檢索與套接字關(guān)聯(lián)的文件描述符 ZMQ_FD選項應檢索與關(guān)聯(lián)的文件描述符指定的套接字.返回的文件描述符可用于將套接字集成到現(xiàn)有的事件循環(huán)中;?MQ 庫應以邊緣觸發(fā)的方式向套接字上的任何未決事件發(fā)出信號通過使文件描述符準備好讀取來實現(xiàn)時尚.

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并將事件循環(huán)推遲到 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

從返回的文件描述符中讀取的能力不必然表明消息可供讀取,或可以寫入,底層套接字;應用程序必須檢索實際事件狀態(tài),隨后檢索 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 套接字的處理程序被觸發(fā)時,您必須在處理我認為的事件之前做更多的工作.未編譯的偽代碼如下

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 到成員函數(shù)就足夠了.

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

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

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

相關(guān)文檔推薦

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++ 中旋轉(zhuǎn)圖像而不使用 OpenCV 函數(shù))
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 無法設(shè)置 SVM 參數(shù))
Convert a single color with cvtColor(使用 cvtColor 轉(zhuǎn)換單一顏色)
主站蜘蛛池模板: 欧美一级久久 | 成人亚洲| 国产日韩一区 | 国产区第一页 | 色综合久久久久 | 一区二区三区四区不卡 | 爱高潮www亚洲精品 中文字幕免费视频 | 日韩av一区二区在线观看 | 亚洲免费在线视频 | 国产日韩91 | 久久久久久久国产精品视频 | 99国产精品久久久 | 国产在线观看一区 | 中文字幕在线观看一区 | 日韩综合一区 | 亚洲精品免费看 | 亚洲一区二区三区在线 | 国产婷婷在线视频 | 国产精品视频网站 | 亚洲v日韩v综合v精品v | 一级午夜aaa免费看三区 | 青青草社区 | 亚洲午夜精品一区二区三区他趣 | 国产乡下妇女做爰 | 凹凸日日摸日日碰夜夜 | 欧美精品久久久 | 毛片av免费看 | 亚洲电影成人 | 亚洲一二三区精品 | 国产成人免费 | 精品一区二区久久久久久久网站 | 毛片视频观看 | 精品视频一二区 | 中文天堂在线一区 | 91精品久久久久久综合五月天 | 精精国产xxxx视频在线播放 | 中文字幕国产视频 | 99在线免费观看视频 | 视频一区二区在线观看 | 91福利网址 | 成人一区在线观看 |