listen() queue length in socket-programing in c?

扶醉桌前 提交于 2019-11-30 19:06:52
Seg Fault

Operating systems actually use larger queues for incoming TCP connections than the one specified to listen(). How much larger depends on the operating system.

 listen(int socket_fd, int backlog)  

For a given listening socket kernal maintains two queue.

  1. An incomplete connection queue - for which SYN has been come but three-way handshaking (TCP) is not done completely. (SYN_RCV state)
  2. A complete connection queue - Three-way handshaking done. (ESTABLISHED state)

backlog argument historically specify sum of both queues. But there is no formal definition of what backlog means.

Berkeley-derived implementation add a fudge factor to the backlog. So total queue length = factor * backlog.

A very detailed and deep explanation given in a book by W. Richard Stevens. Also a table showing the values for seven operating systems can be found in Stevens, Fenner, Rudoff, "Unix Network Programming: The Sockets Network API", Volume 1, Third Edition, Page 108.

The platform is entitled to adjust the specified backlog up or down, according to its minimum and its default. These days the default is more like 500 than five, which is where it started in about 1983. You can't rely on it being what you specified, and there is no API for finding out what it really is, and there is no apparent valid application reason for wanting it to be shorter than the default.

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