使用 boost::asio::async_write 时 TCP 缓冲区正在运行?
TCP buffer in play while using boost::asio::async_write?
我从这个讨论中了解到 boost::asio::async_write 仅将数据写入内核缓冲区。这并不意味着对等方已收到数据。但是,如果我发送大数据包,假设每个数据包大小为 200000 字节,然后我拉网络电缆以突然终止连接。它是否仍会继续报告每个 async_write
写入内核缓冲区的 200000 字节?我的测试表明它没有。它放弃了像 200000 字节这样的大缓冲区,并且不报告发送的所有字节。但是如果它是一个像 30-40 字节这样的小缓冲区,它会一直报告好吗?
问题:
提出这个问题的主要观点是: 是否有一个底层缓冲区大小在某一时刻被填满 async_write
说现在它不能再写了,因为早前预定的数据还没出去?如果是,那么这个底层缓冲区的大小是多少?我可以从 boost::asio::ip::tcp::socket
查询吗?
您可以使用 send_buffer_size 套接字选项 query/change 底层系统套接字缓冲区大小。
操作系统虽然可以 dynamically adjust the socket buffer size and 其最大大小:
tcp_wmem (since Linux 2.4)
This is a vector of 3 integers: [min, default, max]. These
parameters are used by TCP to regulate send buffer sizes. TCP
dynamically adjusts the size of the send buffer from the
default values listed below, in the range of these values,
depending on memory available.
我从这个讨论中了解到 boost::asio::async_write 仅将数据写入内核缓冲区。这并不意味着对等方已收到数据。但是,如果我发送大数据包,假设每个数据包大小为 200000 字节,然后我拉网络电缆以突然终止连接。它是否仍会继续报告每个 async_write
写入内核缓冲区的 200000 字节?我的测试表明它没有。它放弃了像 200000 字节这样的大缓冲区,并且不报告发送的所有字节。但是如果它是一个像 30-40 字节这样的小缓冲区,它会一直报告好吗?
问题:
提出这个问题的主要观点是: 是否有一个底层缓冲区大小在某一时刻被填满 async_write
说现在它不能再写了,因为早前预定的数据还没出去?如果是,那么这个底层缓冲区的大小是多少?我可以从 boost::asio::ip::tcp::socket
查询吗?
您可以使用 send_buffer_size 套接字选项 query/change 底层系统套接字缓冲区大小。
操作系统虽然可以 dynamically adjust the socket buffer size and
tcp_wmem (since Linux 2.4) This is a vector of 3 integers: [min, default, max]. These parameters are used by TCP to regulate send buffer sizes. TCP dynamically adjusts the size of the send buffer from the default values listed below, in the range of these values, depending on memory available.