Re: problem in accept()
- From: "m" <m@xxx>
- Date: Tue, 21 Apr 2009 16:27:26 -0400
Well, you can debug it and see that it doesn't, or you can write your own
test program to illustrate the behaviour. In either case, be aware that the
Windows TCP stack has an optimization for connections via the loopback
adapter so make sure to test with a remote host.
Remember that a socket in the listening state is not ever connected so the
local binding becomes unused as soon as the bound socket is closed without
the need to wait for a remote host to be in a safe state. This is the
difference between closing a socket and closing a connection.
"boris" <somewhere@xxxxxxxxxxx> wrote in message
news:49ee0a56$0$1672$742ec2ed@xxxxxxxxxxxxxxxxx
Your so called "simple test" isn't worth much - how do you know that IIS
doesn't use SO_REUSEADDR option?
SO_REUSEADDRQUOTE
By default, a socket cannot be bound (see bind) to a local address that is
already in use.
...
<<<QUOTE
http://msdn.microsoft.com/en-us/library/ms740476(VS.85).aspx
The TIME_WAIT state is also called 2MSL state...Given the MSL value for anQUOTE
implementation, the rule is: when TCP performs an active close, and sends
the final ACK, the connection must stay in the TIME_WAIT state for twice
the MSL...Another effect of this 2MSL wait is that while the TCP
connection is in the 2MSL wait, the socket pair defining that connection
(client IP address, client port number, server IP address, and server port
number) cannot be reused. The connection can only be reused when the 2MSL
wait is over.Unfortunately most implementations (i.e., the Berkley-derived
ones) impose a more stringent constraint. By default a local port number
cannot be reused while that port number is the local port number of a
socket pair that is in the 2MSL wait.
<<<QUOTE
TCP/IP Illustrated by Richard Stevens (volume 1, page 242)
Boris
"m" <m@xxx> wrote in message news:e4rc1HowJHA.5516@xxxxxxxxxxxxxxxxxxxxxxx
This is complete nonsense and has nothing to do with the OP's problem.
The OP needs to create his socket as OVERLAPED and put the listen loop in
a thread that aborts when the socket is closed (from the main or another
thread). This will allow his application to _shutdown_ properly.
A very simple test should sufice to convince yourself that a bound
listening socket does not exhibit the behaviour you content: initiate
multiple connections to IIS (or your webserver of choice) and restart it.
Use netstat or TCPView to watch the sockets on the server.
"boris" <somewhere@xxxxxxxxxxx> wrote in message
news:49ed3169$0$1655$742ec2ed@xxxxxxxxxxxxxxxxx
To make it more clear: when server TCP socket is closed, it gets into
2MSL state. Default timeout value for that state is 2 minutes. As in OP
scenario: he closed server app and then restarted it. Until 2 minutes
timeout expires, the server app will not be able to bind to same port
(unless SO_REUSEADDR option was specified).
Boris
"boris" <somewhere@xxxxxxxxxxx> wrote in message
news:49ed2f51$0$1634$742ec2ed@xxxxxxxxxxxxxxxxx
Wrong.
Just read a book on TCP/IP.
Boris
"Remy Lebeau" <no.spam@xxxxxxxxxxx> wrote in message
news:eP8sBjhwJHA.528@xxxxxxxxxxxxxxxxxxxxxxx
"boris" <somewhere@xxxxxxxxxxx> wrote in message
news:49e8433b$0$1606$742ec2ed@xxxxxxxxxxxxxxxxx
Most likely, your socket can't bind to same port again.
This is not a binding issue. This is a shutdown issue.
--
Remy Lebeau (TeamB)
.
- References:
- problem in accept()
- From: naveen gupta
- Re: problem in accept()
- From: Remy Lebeau
- Re: problem in accept()
- From: naveen gupta
- Re: problem in accept()
- From: boris
- Re: problem in accept()
- From: Remy Lebeau
- Re: problem in accept()
- From: boris
- Re: problem in accept()
- From: boris
- Re: problem in accept()
- From: m
- Re: problem in accept()
- From: boris
- problem in accept()
- Prev by Date: Re: problem in accept()
- Next by Date: Re: connect() give error 'WSAEINVAL'
- Previous by thread: Re: problem in accept()
- Next by thread: Re: problem in accept()
- Index(es):
Relevant Pages
|