草庐IT

async_receive_from

全部标签

c++ - 具有取消处理的 async_wait 处理程序类成员

这很好用:classcStartSequence{voidTick(){//dosomething}voidWait(){myTimer->expires_from_now(boost::posix_time::seconds(mySecs));myTimer->async_wait(boost::bind(&cStartSequence::Tick,this));}...};我希望能够取消计时器并让处理程序做一些不同的事情voidTick(boost::system::error_code&ec){if(!ec)//dosomethingelse//dosomethingdiffer

c++ - JNI : How to convert a group of data from c++ to Java

我正在尝试使用JNI将一些数据从C++发送到Java。在C++中我有:Array[0]:stringname="myName"intiterations=16floatvalue=15...etc所以我想使用JNI返回Java上的所有数据,我正在尝试这个,但不起作用JNIEXPORTjobjectArrayJNICALLJava_com_testing_data_MainActivity_getDATA(JNIEnv*env,jobjectobj){//1ºCreateatempobjectjobjectdataClass{jstringname;jintiterations;jflo

C++ : generate all subsets from set with one condition

我正在尝试编写代码,通过一个条件从集合中生成所有子集,例如如果我有threshold=2,并且设置了三个:1,2,3,4,51,3,51,3,4然后程序会输出:第一次迭代时的生成集:1=numberoffrequency=32=numberoffrequency=13=numberoffrequency=34=numberoffrequency=25=numberoffrequency=2由于数字2第二次迭代时的生成集:1,3=numberoffrequency=31,4=numberoffrequency=21,5=numberoffrequency=23,4=numberoffre

c++ - 为继承 enable_shared_from_this 的类获取 unique_ptr

通常我更喜欢从工厂返回unique_ptr。最近我遇到了为继承enable_shared_from_this的类返回unique_ptr的问题。此类的用户可能会意外调用shared_from_this(),尽管它不属于任何shared_ptr,这会导致std::bad_weak_ptr异常(或C++17之前的未定义行为,通常作为异常实现)。代码的简单版本:classFoo:publicenable_shared_from_this{stringname;Foo(conststring&_name):name(_name){}public:staticunique_ptrcreate(c

c++ - 继承类中的 shared_from_this() 类型错误(是否有 dyn.type-aware 共享指针?)

我有一个使用enable_shared_from_this的ViewController基类classViewController:publicstd::enable_shared_from_this{//...};和一个child:classGalleryViewController:publicViewController{voidupdateGallery(floatdelta);}问题出现了,当我尝试将我当前的实例传递给第3方时(比如lambda函数被安排在某处)实例(GalleryViewController)会释放一个(罕见的)条件,所以我不能直接捕获“this”,我需要用

c++ - 错误 "lambda is not derived from ' std::function'

我正在尝试将lambda传递给通过可变参数模板定义的std::function,但似乎这在gcc上不起作用。有什么原因,为什么这段代码在gcc7.4.0上不起作用,但在VisualStudio2017上却能正常工作?有没有办法让它在gcc上也能工作,而无需先手动将其转换为std::function?#includetemplateintTestFunction(std::function){return0;}voidTest(){autofce=[](int/*n*/,double/*d*/){};//Thisdoesn'tworkwitherrornomatchingfunction

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++ - boost::asio::async_read 在简单示例中 100% CPU 使用率

在boost::asio中standardexamples在async_accept()之后,socket对象移动到session对象(它处理所有async_read()调用)通过如下初始化它:std::make_shared(std::move(socket_))->start();并且在构造一个session时它又在移动(不是冗余的吗?):session(tcp::socketsocket):socket_(std::move(socket))然后从客户端读取如下:boost::asio::async_read(socket_,...一切顺利。但是,当我尝试使async_read(

c++ - 来自 boost::async() 的 boost::future<> 类型

我从boost::async()得到了意想不到的结果(Boost1.56,Windows:VS2010和VS2012)。#include...autofunc=[](){return123;};autoboostFut=boost::async(func);//boostFut=42;//intentionalerrortorevealdeducedtypeincompilationerror出于某种原因boostFut推导为boost::unique_future而不是boost::unique_future.我做错了什么?注意:在VS2012上,如果我使用std::async(fu