English 中文(简体)
忽略积压值的 listen () 忽略积压值
原标题:listen() ignoring backlog value

据我所知,“强”后背线 连接队列的大小。 任何额外请求如果在当时的大小更大, 将会被删除( 是否正确? )。

现在我有非常简单的程序server.c

socket()
bind()
listen(..., 5)
while(1)
{
  accept()
  read()
  write()
  sleep(3)
  close()
}

现在, 我开始使用 8 个客户端 < 坚固 > 的时间 < / 坚固 > 连接到此服务器 。 令人惊讶的是, 服务器为所有 8 个客户服务, 但它应该只排队 5 个客户 & amp ; 其余 3 个客户端请求应该被拒绝 。 另一个有趣的一点是, 即使我把这个积压值定为 0, 结果还是一样 。 然后, 我试图评论听( ) 电话, 而这8 个客户端的连接都被拒绝 。

有人能对此提供任何投入吗?

最佳回答

积压的参数是有关队列大小的 int 。 所以您不能指望它来做您要做的事 。

"http://pubs.opengroup.org/onlinepubs/009695399/offices/lisen.html" rel="没有跟随 noreferrer"\\code>lisen ()

这 < a href=""https://stackoverflow.com/ questions/511040/lisen-ignores-the-backlog-argument" > 回答 似乎涵盖了这个问题。

我Ubuntu系统上的监听(2)主页引用了更多信息:

The backlog argument defines the maximum length to which the queue of pending connections for sockfd may grow. If a connection request arrives when the queue is full, the client may receive an error with an indication of ECONNREFUSED or, if the underlying protocol supports retransmission, the request may be ignored so that a later reattempt at connection succeeds.

注意上面到处写着"可以"

问题回答

暂无回答




相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...