Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

boost::asio::streambuf empty?

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());

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.

like image 672
Konrad Reiche Avatar asked Jun 12 '26 10:06

Konrad Reiche


1 Answers

Not sure about your code. This works for me:

    boost::asio::streambuf request;
    std::ostream request_stream(&request);
    request_stream << "GET " << queryArgs << " HTTP/1.0\r\n";
    request_stream << "Host: " << serverIp  /* "192.168.0.70" */ << "\r\n";
    request_stream << "Accept: */*\r\n";
    request_stream << "Connection: close\r\n\r\n";

    // Send the request.
    boost::asio::write(socket, request);
like image 189
Bob Yoplait Avatar answered Jun 13 '26 23:06

Bob Yoplait



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!