草庐IT

boost-pool

全部标签

c++ - 如何使用 boost::asio 从网络中断中恢复

我正在编写一个从设备接收数据并处理它的服务器。一切正常,除非网络中断(即,如果我拔下以太网电缆,然后重新连接)。我使用read_until()是因为设备使用的协议(protocol)以特定的字节序列终止数据包。当数据流中断时,read_until()会按预期阻塞。但是,当流再次启动时,它仍然处于阻塞状态。如果我使用Wireshark查看数据流,设备将继续传输并且每个数据包都被网络堆栈确认。但是,如果我查看bytes_readable,它始终为0。如何检测中断以及如何重新建立与数据流的连接?下面是一个代码片段,在此先感谢您提供的任何帮助。[放轻松,这是我的第一个StackOverflow

c++ - boost::split 即使使用 token_compress_on 也会将空字符串推送到 vector

当输入字符串为空时,boost::split返回一个包含一个空字符串的vector。是否可以让boost::split返回一个空vector?MCVE:#include#include#includeintmain(){std::vectorresult;boost::split(result,"",boost::is_any_of(","),boost::algorithm::token_compress_on);std::cout输出:1期望的输出:0 最佳答案 压缩会压缩相邻的分隔符,不会避免空标记。如果您考虑以下几点,您就会

c++ - 如何在 boost::transform_iterator 中使用 phoenix 表达式?

和往常一样,这个问题是错误的。实际问题是:为什么transform_iterator不使用传统的result_of元函数来确定返回类型,而是直接访问UnaryFunc::result_type。发布了一个解决方法的答案。具体来说,是否有办法使phoenix表达式按照std::unary_function概念的预期公开result_type类型?boost::transform_iterator似乎预料到了这一点,从它的src来看,我没有看到一个简单的解决方法。下面是一些重现我遇到的问题的代码:#include#include#include#includeusingnamespaceb

c++ - 如何测量共享内存中 boost 进程间 vector 的大小?

我正在使用boost::interprocess::vector在进程之间共享一些字符串,我想确保我不会溢出它所在的共享内存段。我如何找到vector在内存中占用多少空间,以及一个特殊的段分配字符串将占用多少内存?typedefboost::interprocess::managed_shared_memory::segment_managerSegmentManager;typedefboost::interprocess::allocatorCharAllocator;typedefboost::interprocess::basic_string,CharAllocator>Sh

c++ - BOOST_CHECK_EQUAL(和衍生品)添加自定义消息

我们最近开始使用BoostTest框架,到目前为止很喜欢它。但是,在某些测试中,如果我们可以将自定义消息添加到现有帮助程序,那将会很棒。例如,我可以在mytest和mytest2中获取输出,但在mytest3中找不到输出:#defineBOOST_TEST_MODULEmytests#includeBOOST_AUTO_TEST_SUITE(myunit)BOOST_AUTO_TEST_CASE(mytest){//Thisgiveaniceoutput[2+2!=5]BOOST_CHECK_EQUAL(2+2,5);}BOOST_AUTO_TEST_CASE(mytest2){//T

c++ - 如何使用 boost::asio 连接到 unix 域套接字?

我想通过指定套接字端点的路径名来创建并连接到SOCK_SEQPACKET类型的unix域套接字,但这无法在中编译boost::asiov1.60:usingnamespaceboost::asio::generic;seq_packet_protocolproto{AF_UNIX,IPPROTO_SCTP};//SOCK_SEQPACKETseq_packet_protocol::socketsock(io_service,proto);boost::asio::local::basic_endpointep("/tmp/socket");sock.connect(ep);//does

c++ - 使用模板类 boost python

我创建了一个环形缓冲区,我想使用boost将该类导入Python。当我尝试这样做时,它会出错。ring.cpp:Infunction‘voidinit_module_ring()’:ring.cpp:130:16:error:wrongnumberoftemplatearguments(1,shouldbe4)class_("Ring").Pleasehelpme.ThanksinAdvance.这是我的代码:#include#includeusingnamespacestd;usingnamespaceboost::python;templateclassRing{public:cl

c++ - 使用 boost::property_tree::ptree 将注释写入 ini 文件

有什么方法可以使用boost::property::ptree在ini文件中写入注释吗?类似的东西:voidsave_ini(conststd::string&path){boost::property_tree::ptreept;intfirst_value=1;intsecond_value=2;//Writeacommenttodescribewhatthefirst_valueisherept.put("something.first_value",);//Writeasecondcommentherept.put("something.second_value",second

c++ - 检查类型是否可以作为 boost::lexical_cast<string> 的参数

我有以下特征类(IsLexCastable)来检查是否可以通过调用boost::lexical_cast将类型转换为字符串.它错误地返回true对于vector.#include#include#include#include#include#includeusingnamespacestd;usingnamespaceboost;namespacestd{///AddingtostdsincethesearegoingtobepartofitinC++14.templateusingenable_if_t=typenamestd::enable_if::type;}templates

C++ 如何在 Boost Global Logger 上设置严重性过滤器

几天来我一直在尝试创建一个BoostGlobalLogger以在整个应用程序中使用但我似乎无法在GlobalLogger中设置严重性级别。重要提示:在下面查看Andrey的回答...它被标记为步骤(a)和(b),但我仍然没有做对!直接来自Boost文档here...itwouldbemoreconvenienttohaveoneorseveralgloballoggersinordertoeasilyaccessthemineveryplacewhenneeded.Inthisregardstd::coutisagoodexampleofsuchalogger.Thelibrarypr