jjzjj

SOME_MACRO

全部标签

c++ - Boost::asio socket - 如何在 'throw' 中创建 read_some "timeout"?

所以通常我们会做这样的事情socket.read_some(boost::asio::buffer(buffer,buffer_size));但是如何让它在读取还没有开始的情况下抛出异常比说333秒更长的时间? 最佳答案 您应该考虑使用async_read_some而不是read_some,因为它允许您在读取的同时启动一个新的后台计时器。然后,为您执行的每个新套接字创建一个新计时器:boost::asio::io_serviceio_service;time_t_timertimer(io_service);timer.expire

c++ - 使用挂起的 read_async_some 关闭 boost::asio::serial_port

我正在链接read_async_some()调用以从串行端口异步读取。在某些时候,我需要取消异步读取并在关联的处理程序中检测到这一事实。来自thedocumentationforcancel(),我希望通过检查传递给我的处理程序的error_code来做到这一点:Thisfunctioncausesalloutstandingasynchronousreadorwriteoperationstofinishimmediately,andthehandlersforcancelledoperationswillbepassedtheboost::asio::error::operatio

c++ - boost asio async_read_some 只读取数据片段

我有一个使用boost::asio进行读/写操作的C++服务器-写出消息工作正常-但由于某种原因我无法读取工作我从客户端发送给它的消息是1516位无符号短裤-我的测试消息是这样的:1,34,7,0,0,0,0,0,4,0,0,0,0,0,0现在在服务器上我经常看到这样的事情。读取通常被分解和/或乘以256这是一次发送两次readinglength=8:[134700000]readinglength=3:[102400]readinglength=3:[000]readinglength=8:[134700000]readinglength=6:[102400000]这是第二次发送两次

c++ - 模板 :Name resolution:Point of instantiation: -->can any one tell some more examples for this statement?

这是来自ISOC++标准14.6.4.1实例化点的声明Forafunctiontemplatespecialization,amemberfunctiontemplatespecialization,oraspecializationforamemberfunctionorstaticdatamemberofaclasstemplate,ifthespecializationisimplicitlyinstantiatedbecauseitisreferencedfromwithinanothertemplatespecializationandthecontextfromwhichi

c++ - 将宏名称传递给 X-Macro 列表是否合法

我想到以下是X-macro的更可取的样式技巧:#defineLIST_OF_COLOURS(X)\X(RED)\X(GREEN)\X(BLUE)#defineLIST_OF_FRUIT(X)\X(APPLE)\X(ORANGE)\X(TOMATO)具体来说,将X宏传递给列表,而不是在每次实例化列表时取消定义并重新定义它。这允许:#defineX_LIST(x)x,#defineX_STRING_LIST(x)#x,#defineCOMPREHENSIVE_SETUP(n,l)\enumn{l(X_LIST)};\charconst*n##Names[]={l(X_STRING_LIST

c++ - decltype(some_vector)::size_type 不能用作模板参数

下面的类不编译:template,classAllocator=std::allocator>classMyContainer{public:std::vectordata;std::vector>order;};我收到以下编译器错误:error:type/valuemismatchatargument2intemplateparameterlistfor‘templatestructstd::pair’为什么编译失败,而下面的代码工作正常?template,classAllocator=std::allocator>classMyContainer{public:std::vecto

c++ - write_some 与 write - boost asio

当write_some可能无法将所有数据传输到对等端时,为什么有人要使用它?来自boostwrite_some文档Thewrite_someoperationmaynottransmitallofthedatatothepeer.Considerusingthewritefunctionifyouneedtoensurethatalldataiswrittenbeforetheblockingoperationcompletes.write_some方法在boost中有write方法的相关性是什么?我浏览了boostwrite_some文档,我猜不出什么。

c++ - 从 std::tuple<some_types...> 开始创建子元组

让我们假设一个std::tuple给出。我想创建一个新的std::tuple其类型是在[0,sizeof...(some_types)-2]中索引的类型.例如,假设起始元组是std::tuple.我想获得一个定义为std::tuple的子元组.我对可变参数模板很陌生。作为第一步,我尝试写一个struct负责存放不同类型的原件std::tuple目的是创建一个新的同类元组(如std::tuplenew_tuple)。templatestructtype_list;templatestructtype_list:publictype_list{typedefTtype;};template

c - 我怎样才能与 C 预处理器连接两次并扩展一个宏,如 "arg ## _ ## MACRO"?

我正在尝试编写一个程序,其中一些函数的名称取决于某个宏变量的值,宏变量如下:#defineVARIABLE3#defineNAME(fun)fun##_##VARIABLEintNAME(some_function)(inta);不幸的是,宏NAME()把它变成了intsome_function_VARIABLE(inta);而不是intsome_function_3(inta);所以这显然是错误的做法。幸运的是,VARIABLE的不同可能值的数量很少,所以我可以简单地执行#ifVARIABLE==n并分别列出所有情况,但是有没有聪明的方法来做到这一点? 最

c++ - scanf/字段长度 : using a variable/macro, C/C++

如何在使用scanf时使用变量来指定字段长度。例如:charword[20+1];scanf(file,"%20s",word);此外,使用20+1是否正确(因为它需要在末尾添加\0?)。相反,我想要这样的东西:#defineMAX_STRING_LENGTH20然后charword[MAX_STRING_LENGTH+1];scanf(file,"%"MAX_STRING_LENGTH"s",word);//what'sthecorrectsyntaxhere..?这可能吗?如果它是一个变量怎么样:intlength=20;charword[length+1];scanf(file,