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

时间:2016-11-04 05:55:48

标签: c++ c http tcp raspbian

我在raspberry pi上创建了一个小的c ++ / c http套接字服务器。在过去,我一次只发送/接收1460个数据字节。虽然最近我已经意识到我可以发送更多。我想尽快将数据从服务器发送到客户端。我可以获得客户端可以处理的窗口大小(最大段大小),以便我可以发送该数量的数据。如果它是8192,那么我想在每个服务器套接字发送上传输该数量。能不能给我一些指导如何做到这一点?

1 个答案:

答案 0 :(得分:0)

将getsockopt与TCP_MAXSEG一起使用:

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

来自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.

根据this question,这应该在建立连接后完成,否则将返回一般默认值。