Perl-Sensitive Sunglasses | |
PerlMonks |
Re: TCP server: How to reject connections when busy?by zwon (Abbot) |
on Nov 30, 2011 at 15:53 UTC ( [id://940885]=note: print w/replies, xml ) | Need Help?? |
Backlog is the maximum number of established connections (i.e. handshake was completed) that may be placed in accept(2) queue. On BSD (and Linux) value 0 is actually means 1, so here you already have a problem, there's always one place in the queue. But even if all places in queue are taken TCP continues accepting connection requests, it doesn't reject them. Consider following example server:
Now, if I try to establish four simultaneous connections to this server using netcat from different terminals:
all this connections will be accepted. Here's what netstat shows me:
As you can see on the client side all connections are in ESTABLISHED state. From the server side one connection (from port 44390) was ESTABLISED and accepted, another connection (from port 44392) ESTABLISHED but not yet accepted, it is in accept queue, and two more connections are in SYN_RECV state, that means that server sent SYN-ACK to client, but ignoring ACKs from client till there will be a place in the accept queue (just wait a minute). PS: ISBN 0201633469 is highly recommended.
In Section
Seekers of Perl Wisdom
|
|