问题描述
我已经写2对codeS( server.c
和 client.c
),在Linux中。一个用于UNIX域 AF_UNIX
其他与因特网域名 AF_INET
。两者都工作正常!
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
. Both are working fine!
听()
被称为作为backlog队列长度= 3 在这两个服务器
listen(sockfd, 3);
在UNIX域(AF_UNIX):当一个客户端与服务器相连,如果我尝试更多的客户端连接到服务器。三是保留在队列中,第四请求被拒绝。 ( - 在等待队列3,因为我需要)。
In UNIX domain (AF_UNIX): While one client is connected with server, If I try to connect more clients to server. Three are kept in queue, and request of fourth is declined. (as I desired - 3 in waiting queue).
互联网域(AF_INET):三个以上的申请都保存在一个未决队列。
In INTERNET domain (AF_INET): Request of more than three are kept in a pending queue.
为什么不从第四个客户端的请求被拒绝,即使在backlog队列长度为3?又为何)的行为听(
(及其他)协议相关?
Why isn't a request from a fourth client rejected, even when the backlog queue length is three? And why is the behavior of listen()
(and others) protocol dependent?
推荐答案
操作系统实际使用超过指定一个监听传入的TCP连接队列较大()
。大多少取决于操作系统上。
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.
- 一个不完整的连接队列 - 为其SYN已经来了,但三次握手(TCP)没有完全完成。 (SYN_RCV状态)
- 一个完整的连接队列 - 三次握手完成。 (ESTABLISHED状态)
的积压的说法在历史上同时指定队列的总和。但是,什么样的没有正式定义积压的意思。
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
.
在一本由理查德·史蒂文斯给予了非常详细和深入的解释。也显示出七个操作系统值的表可在史蒂文斯,芬纳,Rudoff,<一找到href=\"http://books.google.co.in/books?id=ptSC4LpwGA0C&printsec=frontcover&dq=unix%20network%20programming%20the%20sockets%20network%20api%20volume%201%20third%20edition%20google%20books&source=bl&ots=Kr5xNpglTq&sig=w06efLjz6Qsl2Z6sCWrDv0XYIZk&hl=en&sa=X&ei=QON7UNuXDobUrQeT_ICADQ&ved=0CDAQ6AEwAA#v=onepage&q&f=false\"相对=nofollow> unix网络编程:套接字网络API ,第1卷,第三版,108页
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.
这篇关于听在C在插座编程()队列长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!