[ale] listen()

cfowler cfowler at outpostsentinel.com
Tue Feb 11 13:55:55 EST 2003


Its not a problem.  I want the others to get a connection refused
message.  This is for ttyd.  Thus can only accept one connection per
serial port being serviced.

The problem is that listen(sock, 0) does not error them out, it queues
them up.

NOTES
       The  behaviour  of  the  backlog  parameter on TCP sockets
       changed with Linux 2.2.  Now it specifies the queue length
       for completely established sockets waiting to be accepted,
       instead of the number of incomplete  connection  requests.

The change noted above is a problem.  It seems that the kernel
establishes the connections and then connections are in a state waiting
to be accepted.



On Tue, 2003-02-11 at 13:46, Chuck Huber wrote:
> On Tue, Feb 11, 2003 at 09:29:16AM -0700, Joe wrote:
> > cfowler <cfowler at outpostsentinel.com> writes:
> > 
> > > I'm writing a server that will only accept one connection at a time.  IT
> > > will only service one.  It will then accept a new one after the one
> > > being serviced has terminated.  My questions is that listen(int socket,
> > > int backlog) does not do this for me.  I'm setting backlog to 0 and I've
> > > got clients waiting in the wings to be accept()ed.
> 
> That's your problem.  Setting a backlog of zero will cause an error to be
> issued to clients trying to connect (resource busy, if I recall correctly).
> The value of the backlog passed to listen() is dependent on how fast you
> can accept() a connection and how fast you expect connect requests to
> arrive balanced with system resources.  A typical value is 5.  
> 
> As Joe mentioned, forking a child to accept the connection gets the
> parent back to an accept() quicker.
> 
> In your single-threaded scenario, there could be a long period before
> you arrive back at an accept().  As such, the backlog for listen()
> needs to be larger - perhaps 10 - to allow connection requests to be
> queued rather than errored.
> 
> Enjoy,
>     - Chuck
> -- 
> "The purpose of encryption is to protect good people
> from bad people, not to protect bad people from the government."
>      Scott McNealy, CEO Sun Microsystems
> "The best way for government to control people is to remain in
>    a constant threat of war." ---Karl Marx
> "They that can give up essential liberty to obtain a little temporary
>    safety deserve neither liberty nor safety." -- Benjamin Franklin


_______________________________________________
Ale mailing list
Ale at ale.org
http://www.ale.org/mailman/listinfo/ale






More information about the Ale mailing list