TCP套接字服务器c++/c窗口大小

TCP socket server c++/c window size

本文关键字:窗口大小 c++ 套接字 服务器 TCP      更新时间:2023-10-16

我在树莓派上创建了一个小型c++/c http套接字服务器。在过去,我一次只发送/接收1460个数据字节。虽然最近我意识到我可以发送更多。我想发送数据从服务器到客户端尽可能快。我是否可以获得客户端可以处理的窗口大小(最大段大小),以便我可以发送该数量的数据。假设它是8192,那么我想在每个服务器套接字发送上传输这个数量。谁能给我点建议,告诉我该怎么做?

在TCP_MAXSEG中使用getsockopt:

int mss;
socklen_t len = sizeof mss;
getsockopt(fd, IPPROTO_TCP, TCP_MAXSEG, &mss, &len);

From man tcp:

  TCP_MAXSEG
         The maximum segment size for outgoing TCP packets.  In Linux 2.2
         and  earlier,  and  in Linux 2.6.28 and later, if this option is
         set before connection establishment, it  also  changes  the  MSS
         value  announced to the other end in the initial packet.  Values
         greater than the (eventual) interface MTU have no  effect.   TCP
         will  also  impose its minimum and maximum bounds over the value
         provided.

根据这个问题,应该在连接建立后执行此操作,否则将返回一个通用的默认值