About boost :: asio sockets and blocking

So, I tried to boost boost :: asio and tested blocking echo examples. They do not seem to completely block. Not as I expected.

Is there any way to get rid of any buffering or what might have the smallest buffer size? It seems like 10,000 bytes is too small.

The following code runs 2 entries before they are locked. If I add the argument boost :: asio :: transfer_exactly (10000) for the record, it is still 2. boost :: asio :: transfer_exactly (5000) gets me 5 records.

So how does this network / io / asio work? For example, if I wanted to send only one byte and wait until it reaches the other end, without any additional messages.

Server:

boost::asio::io_service io_service;

tcp::acceptor a(io_service, tcp::endpoint(tcp::v4(), 12346));
tcp::socket sock(io_service);

a.accept(sock);
sock.non_blocking(false);
boost::asio::socket_base::send_buffer_size option(10000);
sock.set_option(option);

while(true) {
    char data[10000];

    boost::asio::socket_base::bytes_readable bytes_readable_cmd(true);
    sock.io_control(bytes_readable_cmd);
    std::size_t bytes_readable = bytes_readable_cmd.get();
    if(bytes_readable) {
        /**/
    }

    boost::asio::write(sock, boost::asio::buffer(data, 10000));
    printf("#\n");Sleep(10);
}

Customer:

boost::asio::io_service io_service;

tcp::resolver resolver(io_service);
tcp::resolver::query query(tcp::v4(), "localhost", "12346");
tcp::resolver::iterator iterator = resolver.resolve(query);

tcp::socket sock(io_service);
boost::asio::connect(sock, iterator);
sock.non_blocking(false);
+3
source share
1

, write .

msdn:

, . , .

, , , .

64 ( 65537) .

, Asio, TCP . .

, , .. .

+4

All Articles