From: Andrew Morton <akpm@linux-foundation.org>
To: netdev@vger.kernel.org
Cc: bugzilla-daemon@bugzilla.kernel.org,
bugme-daemon@bugzilla.kernel.org, florent.cloirec@free.fr
Subject: Re: [Bugme-new] [Bug 13688] New: backlog parameter of listen is not working with TCP
Date: Wed, 1 Jul 2009 11:49:32 -0700 [thread overview]
Message-ID: <20090701114932.a2f4a2e4.akpm@linux-foundation.org> (raw)
In-Reply-To: <bug-13688-10286@http.bugzilla.kernel.org/>
(switched to email. Please respond via emailed reply-to-all, not via the
bugzilla web interface).
On Wed, 1 Jul 2009 18:39:07 GMT
bugzilla-daemon@bugzilla.kernel.org wrote:
> http://bugzilla.kernel.org/show_bug.cgi?id=13688
>
> Summary: backlog parameter of listen is not working with TCP
> Product: Networking
> Version: 2.5
> Kernel Version: 2.6
> Platform: All
> OS/Version: Linux
> Tree: Mainline
> Status: NEW
> Severity: normal
> Priority: P1
> Component: IPV4
> AssignedTo: shemminger@linux-foundation.org
> ReportedBy: florent.cloirec@free.fr
> Regression: No
>
>
> Created an attachment (id=22171)
> --> (http://bugzilla.kernel.org/attachment.cgi?id=22171)
> little test server
>
> When creating a server I usually create a socket, bind it to any address and
> call listen to limit the queue size, then I call accept in a loop to handle
> clients one by one.
>
> In a particular case I wanted to serve only 1 client and refuse the other
> connection attempts. I tried any value for the backlog parameter, whatever I
> use the server is not refusing any connection, though the queue should be full.
> The SYN+ACK handshake is completed everytime.
>
> To be sure this is a bug I checked this with BSD and Windows, I can confirm
> that it refuses connections if the max queue size specified with backlog is
> reached (Note that backlog is not exactly the queue size with these systems,
> there is a 3/2 factor, I don't know why).
>
> Maybe this implementation for linux kernel is wanted even if it is not posix
> compliant, but I did not find anywhere why this is working like this. If this
> is not a bug, could someone explain me the usefullness of the backlog
> parameter?
>
> I attached a little test program with which anyone should be able to test this
> by connecting multiple telnet to.
>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <netinet/ip.h>
int main(void)
{
int servsock = 0;
int clientsock = 0;
struct sockaddr_in servaddr;
struct sockaddr_in clientaddr;
socklen_t clientaddrlen;
struct in_addr client_addr;
servsock = socket(AF_INET, SOCK_STREAM, 0);
//fcntl(servsock, F_SETFL, O_NONBLOCK);
if(servsock != -1)
{
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(6256);
inet_aton("0.0.0.0", &client_addr);
servaddr.sin_addr = client_addr;
if(bind(servsock, &servaddr, sizeof(servaddr)) != -1)
{
if(listen(servsock, 0) != -1)
{
while(1)
{
printf("waiting for clients\n");
clientsock = accept(servsock, &clientaddr, &clientaddrlen);
if(clientsock != -1)
{
printf("client accepted, now sleep 60 sec\n");
sleep(60);
printf("60 sec have elapsed, closing connection\n");
close(clientsock);
}
else
{
printf("accept error: retrying in 1 sec...\n");
sleep(1);
}
}
}
else
{
printf("listen failed\n");
}
}
else
{
printf("bind failed\n");
}
}
else
{
printf("socket creation failed\n");
}
return 0;
}
next parent reply other threads:[~2009-07-01 18:49 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <bug-13688-10286@http.bugzilla.kernel.org/>
2009-07-01 18:49 ` Andrew Morton [this message]
2009-07-01 21:10 ` [Bugme-new] [Bug 13688] New: backlog parameter of listen is not working with TCP Florian Westphal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090701114932.a2f4a2e4.akpm@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=bugme-daemon@bugzilla.kernel.org \
--cc=bugzilla-daemon@bugzilla.kernel.org \
--cc=florent.cloirec@free.fr \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).