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

前端 未结 2 1508
说谎
说谎 2021-01-04 21:49

I have written two pair of codes(server.c and client.c) in Linux. One for UNIX-domain AF_UNIX other for INTERNET-domain AF_INET<

2条回答
  •  迷失自我
    2021-01-04 22:33

    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.

提交回复
热议问题