Mohammad Razeghi
Mohammad Razeghi

Reputation: 1594

boost::iostream readline stop after 4096 bytes

I'm writing a program that transfer large data over network and I'm using boost asio iostream to do it.

here's my code :

boost::asio::ip::tcp::iostream s;
s.connect("localhost","4000"); 
string ss;
getline(s,ss);

but getline does not read a complete line when output is more than 4096 charachters and it break it into two messages.

what is the right way to read a single line when input is large?

Upvotes: 1

Views: 322

Answers (1)

sehe
sehe

Reputation: 392833

I'm not reproducing this with

  • Ubuntu linux 14.10 64 bit
  • gcc 4.8.2
  • boost_1_57
  • localhost traffic

Did you check there are no linefeeds in the input?


If I feed it a continues stream of input, I do not detect such issues. E.g. with netcat, Live On Coliru

for a in {1..1024}; do echo -n 0123456789; done | nc -l 6767& 

This sends 10k of data without linefeeds

./a.out | wc 

This counts lines, words and characters returned by our code:

 0       1   10240

Code

for reference

#include <boost/asio.hpp>
#include <iostream>

int main() {
    boost::asio::ip::tcp::iostream socket("127.0.0.1","6767"); 

    std::string as_read;
    std::getline(socket,as_read);

    std::cout << as_read;
}

Upvotes: 1

Related Questions