I am trying to read big amount of data asyncrhonous, I know that with "others" libraries in syncronous mode I need call read some times by chuncks because tcp is a stream and the windows size is limited. So I think that need do it with async_read from boost asio, but the callback is called for short data(eg: 1024), when the amount of data grow(eg: max_length = 80000 > 65536) the callback is not called, so what are making wrong?, this is an example the produce my problem:
#include <cstdio>
#include <thread>
#include <boost/asio/io_service.hpp>
#include <boost/asio/connect.hpp>
#include <boost/asio/read.hpp>
#include <boost/asio/streambuf.hpp>
#include <boost/asio/ip/tcp.hpp>
namespace ba = boost::asio;
enum { max_length = 1024 };
int main() {
ba::io_service io_service;
ba::ip::tcp::socket sk(io_service);
ba::ip::tcp::resolver resolver(io_service);
ba::connect(sk,
resolver.resolve(ba::ip::tcp::resolver::query{ba::ip::tcp::v4(),
"127.0.0.1",
"8881"}));
char request[max_length];
ba::async_read(sk,
ba::buffer(request, max_length),
[](const boost::system::error_code& err, std::size_t){
if (!err) {
std::printf("Callback without error!\n");
} else {
std::fprintf(stderr, "Callback with error!\n");
}
});
io_service.run_one();
// wait the transtition in the async thread.
std::this_thread::sleep_for(std::chrono::milliseconds{1000});
return EXIT_SUCCESS;
}
Aucun commentaire:
Enregistrer un commentaire