提高:: ASIO ::流缓冲空的? [英] boost::asio::streambuf empty?

查看:195
本文介绍了提高:: ASIO ::流缓冲空的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用boost :: ASIO ::流缓冲写的ostream我升压插座。

I am using boost::asio::streambuf to write a ostream to my boost socket.

Name name;
name.set_name("platzhirsch");

boost::asio::streambuf b;
std::ostream os(&b);

ZeroCopyOutputStream *raw_output = new OstreamOutputStream(&os);
CodedOutputStream *coded_output = new CodedOutputStream(raw_output);

coded_output->WriteVarint32(name.ByteSize());
name.SerializeToCodedStream(coded_output);

socket.send(b.data());

然而,通过发送返回为size_t是0,我怀疑没有任何数据都发送。也正因为客户端套接字抛出可怕异常。我问,如果有什么奇怪我的code。

However, size_t returned by send is 0. I am suspicious that no data is sent at all. Also because the client socket throws horrible exceptions. I am asking, if there is something strange about my code.

在换句话说,我可以测试是否流缓冲为空,或者写入的数据是实实在在地存在着。

In other words, can I test if streambuf is empty or if the data written to it is really there.

推荐答案

这是没有提升的问题:: ASIO,这是谷歌的protobuf的问题。

It was no problem of boost::asio, it was a problem of Google protobuf.

为了冲codedOutputStream,他们必须被删除:

In order to flush the CodedOutputStream, they have to be deleted:

ZeroCopyOutputStream *raw_output = new OstreamOutputStream(&os);
CodedOutputStream *coded_output = new CodedOutputStream(raw_output);

coded_output->WriteVarint32(name.ByteSize());
name.SerializeToCodedStream(coded_output);

delete coded_output;
delete raw_output;

socket.send(b.data());

这篇关于提高:: ASIO ::流缓冲空的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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