int nagle_status = 1;
int result = setsockopt(sock, //socket的文件描述符
                        IPPROTO_TCP,
                        TCP_NODELAY,
                        (char *) &nagle_status, 
                        sizeof(int));    // 1 - on, 0 - off
 if (result < 0){
 	throw std::runtime_error("Failed to change the Nagle");
 }
1

#include <netinet/tcp.h>

默认 TCP_NODELAY=0,表示关闭 TCP_NODELAY 选项,也就是说,关闭了禁止延迟,也就是说有延迟,即采用了 Nagle 算法,会延迟 40ms

Logo

加入社区!打开量化的大门,首批课程上线啦!

更多推荐