Boost.Asio的iostream的冲洗不工作? [英] Boost.Asio iostream flush not working?

查看:129
本文介绍了Boost.Asio的iostream的冲洗不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何想法,为什么 stream.flush(); 将无法正常工作

any ideas why stream.flush(); won't work?

boost::asio::ip::tcp::iostream stream("localhost","5000");
assert(stream.good());  
stream << 1;
stream.flush();
while(true);

如果环路排除这只是满脸通红,该行

的boost :: this_thread ::睡眠(升压::了posix_time ::秒(1));

执行(晚得多)。

it's only flushed if the loop is removed and the line
boost::this_thread::sleep(boost::posix_time::seconds(1));
is executed (much later).

感谢

更新:
我做了一些更多的调试,问题其实不是刷新命令。如果我让我的code连接到服务器的netcat一切工作正常。我认为问题是,无论是客户机和服务器在同一个过程(Ⅰ创建两个威胁中的一种作为服务器一个作为客户机)。当我把它们放在单独的进程一切正常,但是当两者都在同一个进程转移到摊位睡眠叫...(这仅仅是为了测试的原因,后来都将在不同的服务器上运行)。

Update: I did some more debugging and the problem is in fact not the flush command. If I let my code connect to a netcat server everything works fine. I assume the problem is that both client and server are in the same process (I create two threats one acts as a server one as a client). When I put them in separate processes everything works fine, but when both are in the same process the transfer stalls until sleep is called... (this is only for testing reasons, later both will run on different servers).

平台是WindowsXP。

Platform is WindowsXP.

任何想法,为什么发生这种情况?

Any ideas why this is happening?

推荐答案

你怎么知道刷新不起作用?
我怀疑你的,而(真)使您的系统非常重的负担。
这可以prevent运行收件人。

How do you know flush doesn't work? I suspect that your while(true) puts very high load on your system. This can prevent the recipient from running.

在尝试其他主机上的同一code。与收件人检查。

Try the same code with recipient on an other host to check.

更新:
我认为这个问题是空的,而(真);
我会用这样的:

Update: I think the problem is the empty while(true); I would use something like:

while(true) {
    sleep(1);
}

或在了nanosleep的ctime头两个定义。
最后,是的,我相信正在运行的服务器和客户端在同一个
过程将让你在更多的麻烦。

or nanosleep both defined in header ctime. Finally yes I believe running server and client in the same process will get you in more trouble.

/托比亚斯

这篇关于Boost.Asio的iostream的冲洗不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆