替代方法来延迟我的程序而不睡觉,因为在C ++中使用异步IO?(Alternate ways to delay my program without sleeping because of the use of asynchronous IO in C++?)
除了睡觉之外,我还有一些关于使用C ++延迟程序的替代方法的问题。
我有我的程序的一部分接收和发送UDP数据包到控制器。 这部分程序必须异步运行。 为了减少此提供程序的开销,我决定使用异步IO来接收UDP数据包,而不是使用单独的线程来监视套接字。
我遵循这个 sigaction的例子来完成这个。 我注意到,如果我在尝试使用这个sigaction的时候尝试使用usleep,那么每当我收到一个数据包的时候就会打破我的睡眠。 这种说法是有道理的,因为我认为sigaction是由CPU上的某种中断触发的,这可能会阻止CPU进入休眠状态。 如果任何人有一个很好的解释为什么会发生这种情况,我会很好奇知道。 我的问题是,有时我必须连续发送几个数据包,并且需要确保延迟它们,否则我的控制器会错过它们。
我通常会使用睡眠来延迟发送数据包,但现在我不能因为它被我的sigaction破坏了。 我曾想过可能会忙于等待,但这可能太不一致了。 我也有关于可能使用一个定时清空的数据包队列,但似乎可能有一个更简单的解决方案。
除了睡眠之外,还有其他延迟发送数据包的方式吗? 有没有办法设置我的异步IO,所以它不会打破睡眠? 我是以错误的方式解决这个问题吗?
I have a questions regarding alternate ways to delay a program in C++ besides sleeping.
I have a part of my program that receives and sends UDP packets to a controller. This part of the program has to run asynchronously. In order to reduce the overhead of this provider I decided to use asynchronous IO to receive the UDP packets rather than having a separate thread monitor the socket.
I followed this example of a sigaction to accomplish this. I noticed that if I try to use usleep while this sigaction is active it will break my sleep whenever I receive a packet. This kind of makes sense since I assume the sigaction is triggered by some sort of interrupt on the CPU which might stop the CPU from sleeping. If anyone has a good explanation for why this happens I would be curious to know. My issues is that there are times where I have to send several packets in succession and need to make sure to delay them otherwise they are missed by my controller.
I usually would use a sleep to delay the sending of the packets, but now I can't because of it gets broken by my sigaction. I have thought about maybe using a busy wait, but it might be too inconsistent. I have also though about maybe using a queue of packets that is emptied at regular intervals using a timer, but it seems like there might be a simpler solution.
Is there another way to delay the sending of the packets besides sleeping? Is there a way to set up my asynchronous IO so it does not break the sleep? Am I going about this in the wrong way?
原文:https://stackoverflow.com/questions/26167272
最满意答案
如果你在unix上使用命令提示符,难道你不能用
>
将输出重定向到一个文本文件吗?phpunit ArrayTest > MyArrayTestOutput.txt
大多数IDE也可以让你将他们的缓冲区/终端的输出复制/粘贴到任何你心中所渴望的地方。
if you're using the command prompt on unix, couldn't you just use the
>
to redirect the output to a text file?phpunit ArrayTest > MyArrayTestOutput.txt
Most IDEs will also let you copy/paste the output of their buffer/terminal to wherever your heart desires.
相关问答
更多-
实现目标的最佳方法是使用模拟文件系统。 我建议使用vfsStream : $ composer require mikey179/vfsStream 首先,我必须提一下,如果使用无效参数调用此函数,则fread只返回false 。 如果发生任何其他错误,它将返回已写入的字节数。 所以你必须添加另一张支票: class SomeClass { public function save($content, $path) { // ... if (($handle ...
-
如果PHPUnit检测到测试方法结束时的输出缓冲级别与开始时的级别不同,则会报告该消息。 这是由于它使用自己的输出缓冲区并检查测试没有输出。 因为PHPUnit中没有选项可以忽略它,所以您需要找到代码中的输出缓冲开始但没有结束(或结束太多)并解决该问题的原因。 这可能真的很难实现,因为没有提示,输出缓冲开始,但您可以在源代码(和库)上使用全文搜索来识别候选。 然后查找Exceptions,这可能会破坏正常的程序流程,并因此阻止ob_end_flush() (或类似的)。 The message is rep ...
-
在测试抽象类时,您可以使用PHPUnit的模拟功能。 添加方法的示例如下所示: public function testAdd() { /* @var $calculator \App\Module\Calculator\calculator|\PHPUnit_Framework_MockObject_MockObject */ $calculator = $this ->getMockBuilder('App\Module\Calculator\calculator') ...
-
您需要与数据库($ wpdb)建立活动连接,并使用所有凭据进行实例化,然后在测试中使用它。 尽量避免全局变量,在构造函数或setter中传递它。 此外,您可能希望查看一些准备好的wordpress测试工具,如http://wptest.io/ You need an active connection to the database ($wpdb), instantiated with all credentials, then use it in your test. Try to avoid globa ...
-
本书中使用的composer.json文件行: phpunit/phpunit" : "3.7.* 我已经改变了phpunit/phpunit" : "3.7.*到phpunit/phpunit" : "4.5.*作为4.5版本的PHPUnit是当前的稳定版。 然后,当然: php composer.phar update然后这个将很好地工作: ZF2_PATH=`pwd`/vendor/zendframework/zendframework/library \php vendor/phpunit/phpu ...
-
是否存在0或1(真/假)的整体PHPunit测试结果(Does an overall PHPunit Test Result of 0 or 1 (True / False) exist)[2023-08-09]
我想你可以检查phpunit命令的退出状态在你的shell中,试试吧 phpunit successfulTest.php echo $? phpunit failingTest.php echo $? 结果应该是不同的。 我想通过记住phpundercontrol的人如何编写他们的phpunit目标来解决这个问题 I think you can check the exit status of the phpunit command In your shell, try phpunit success ... -
你必须测试你班上的每一种方法。 你有构造函数,也应该进行测试,看看它是否为你的属性设置模型,以及你的受保护方法。 你应该用嘲弄来嘲笑你的模型。 它可以安装 $ composer require mockery/mockery 然后在您的测试文件中:如果你在unix上使用命令提示符,难道你不能用>将输出重定向到一个文本文件吗? phpunit ArrayTest > MyArrayTestOutput.txt 大多数IDE也可以让你将他们的缓冲区/终端的输出复制/粘贴到任何你心中所渴望的地方。 if you're using the command prompt on unix, couldn't you just use the > to redirect the output to a text file? phpunit ArrayTest > ...
PHPunit测试错误(PHPunit test error)[2022-01-04]
我写了一些有意见的工作文章: class ModelSaleCustomerTest extends PHPUnit_Framework_TestCase { protected $object; protected function setUp() { define('DB_PREFIX', ''); $mockRegistry = $this->getMock('Registry', ['get']); $db ...是否有可能在每次PHPUnit测试失败后运行一个函数?(Is it possible to run a function after every PHPUnit test failure?)[2024-01-19]
尝试使用方法tearDown()或onNotSuccessfulTest() http://phpunit.de/manual/current/en/fixtures.html Try to use the method tearDown() or onNotSuccessfulTest() http://phpunit.de/manual/current/en/fixtures.html相关文章
更多- 关于如何参与到开源项目中《How To Succeed In Open Source ( In Ways You Haven't Considered Yet )》
- Java 流(Stream)、文件(File)和IO
- 《编程之道 Java》(Program JAVA)[ISO]
- java server怎样和c++ client实现SSL通信??
- iotop命令实时监听磁盘IO
- Hadoop core之IO
- Java:IO/NIO篇,读写属性文件(properties)
- 《标准C/C++编程系列视频教程》共17天/更新完毕[压缩包]
- 关于java io流关闭的问题
- 谁给推荐一个C++的JSON库
最新问答
更多- 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
- 如何通过引用返回对象?(How is returning an object by reference possible?)
- 矩阵如何存储在内存中?(How are matrices stored in memory?)
- 每个请求的Java新会话?(Java New Session For Each Request?)
- css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
- 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
- xcode语法颜色编码解释?(xcode syntax color coding explained?)
- 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
- 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
- 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
- 西安哪有PLC可控制编程的培训
- 在Entity Framework中选择基类(Select base class in Entity Framework)
- 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
- 电脑二级VF有什么用
- Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
- 金华英语角.
- 手机软件如何制作
- 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
- 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
- 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
- Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
- 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
- python的访问器方法有哪些
- DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
- 在Ruby中对组合进行排序(Sorting a combination in Ruby)
- 网站开发的流程?
- 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
- 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
- 透明度错误IE11(Transparency bug IE11)
- linux的基本操作命令。。。