Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Re: Newbie question: how to keep a socket listening? (http://www.velocityreviews.com/forums/t346433-re-newbie-question-how-to-keep-a-socket-listening.html)

Jp Calderone 06-25-2005 01:30 AM

Re: Newbie question: how to keep a socket listening?
 
On Fri, 24 Jun 2005 21:21:34 -0400, Peter Hansen <peter@engcorp.com> wrote:
>ncf wrote:
>> Heh, like I said. I was not at all sure. :P
>>
>> Nevertheless, could this be the problem? =\

>
>You *may* correct, mainly because the OP's code doesn't appear to spawn
>off new threads to handle the client connections, which means he can
>handle only one connection at a time. Specifically, while he is talking
>to one client he is not also in an accept() call on the server socket,
>which means there will be (because of the listen(1) call) only a single
>pending connection allowed in the backlog.
>
>I haven't attempted a thorough analysis... just this much, trying to see
>whether it is obvious that the listen(1) is at fault -- and it's not
>obvious. I thought this response might clarify the meaning of listen(1)
>a little bit for some folks nevertheless.


The argument to listen() is only a _hint_ to the TCP/IP stack. Linux, at least, will not create a buffer large enough for only a single connection. You can test this easily: create a socket, bind it to an address, call listen(1) on it, and *don't* call accept(). Telnet (or connect somehow) repeatedly, until your connection is not accepted. On my system (Linux 2.6.10), I can connect successfully 8 times before the behavior changes.

Jp

Grant Edwards 06-25-2005 01:38 AM

Re: Newbie question: how to keep a socket listening?
 
On 2005-06-25, Jp Calderone <exarkun@divmod.com> wrote:

> The argument to listen() is only a _hint_ to the TCP/IP stack.
> Linux, at least, will not create a buffer large enough for
> only a single connection. You can test this easily: create a
> socket, bind it to an address, call listen(1) on it, and
> *don't* call accept(). Telnet (or connect somehow)
> repeatedly, until your connection is not accepted. On my
> system (Linux 2.6.10), I can connect successfully 8 times
> before the behavior changes.


I had noticed that once upon a time. I had forgotten that 8
was the minimum, but I do remember that 1 didn't result in a
second connect failing.

--
Grant Edwards grante Yow! Ha ha Ha ha Ha ha
at Ha Ha Ha Ha -- When will I
visi.com EVER stop HAVING FUN?!!


All times are GMT. The time now is 06:32 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57