boost::asio with no_delay not possible?

[亡魂溺海] 提交于 2019-12-02 02:15:49

The async_connect() free function will close the socket:

If the socket is already open, it will be closed.

However, the socket.async_connect() member function will not close the socket:

The socket is automatically opened if it is not already open. If the connect fails, and the socket was automatically opened, the socket is not returned to the closed state.

The following code will set the no_delay option on an open socket, and then initiate an asynchronous connect operation for the open socket:

socket.open(tcp::v4());
socket.set_option(tcp::no_delay(true));
socket.async_connect(endpoint, handler);

Just set it right after connection. Nagle algorithm works after you send any data before kernel received ASK packet. So it does not matter for connect operation. Just set it right after connect, before any send.

socket.async_connect(ep, yield);
socket.set_option(tcp::no_delay(true));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!