Re: Async Socket IO Question

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Logically I knew that... :) yes, the connection has not been closed and is
still pending timeout.

Thanks for the link.

But what happens if 500 people hit your socket and then all hangup? You
will get all the accepts and start receives on them. But then what happens?
Did that just kill your IOCP pool of threads?

Thanks.


"Chris Mullins" <cmullins@xxxxxxxxx> wrote in message
news:Okj4LN%235GHA.2188@xxxxxxxxxxxxxxxxxxxxxxx
I think you're mostly bumping into Socket Timeout issues.

If you kill the process of your client app, the TCP session isn't cleanly
shut down. Your server still thinks the connection exists. You can verify
this using "NetStat -a". You'll see your connection still in there.

When your server sends to the client app, that send happens just fine (the
TCP Session still there). After a few moments, your TCP send will timeout,
and you'll get an error. At this point the TCP Session is torn down.

Just because it's amusing, I have had more bugs in socket shutdown code
than all the other areas of networking put together. There are so many
ways, and so many conditions, that can cause a TCP session to be torn down
that it's just depressing.

Here's an MS KB article that goes into how to adjust your timeouts:
http://support.microsoft.com/?kbid=170359

Note: I don't recommend adjusting your timeouts - but you do need to have
a solid understanding of what's going on.

--
Chris Mullins, MCSD.NET, MCPD:Enterprise
http://www.coversant.net/blogs/cmullins


"EmeraldShield" <emeraldshield@xxxxxxxxxxxxxxx> wrote in message
news:%23Q$abF%235GHA.4644@xxxxxxxxxxxxxxxxxxxxxxx
Hi all. I have been digging around trying to find an answer to a few
questions that are bugging me. I am hoping someone here can help.

1 - If you start an Async IO (BeginAccept) and the client hangs up what
happens? The docs really don't tell you one way or the other. In my
local testing many of the sockets are never getting released for some
reason. I am not seeing my delegate called. I used an Interlock
increment on each begin and a decrement on each delegate to track it and
sometimes they come through, and sometimes they don't. Very odd. What
is the correct behavior?

2 - Why does the .Connected property not update? I have read the docs
and tried lots of tests. It still does not appear to work.

try
{
// Attempt to ensure we are still connected...
byte[] temp = { 0x00 };
// I tried blocking and non-blocking didn't make a difference
sp.Client.Blocking = false;
// This is the MS recommended way. It ALWAYS returns 0 for me and
connected is not updated.
int res = sp.Client.Send(temp, 0, 0);
// I added this as an additional test and the same thing happens.
Always get back 0.
res = sp.Client.Receive(temp, 0, SocketFlags.None);
// If we get here we are still connected and alive...
}
catch( SocketException e )
{
if( e.NativeErrorCode.Equals(10035) )
{
// Still connected - the call would black
}
else
{
// We are disconnected
TimeoutOccured(ref sp);
return (false);
}
}

This app is a socket server that has remote clients connect. I can
manually telnet to the app, watch it start a read, and then kill the
telnet app. I know the socket is gone. I look in the process list and
telnet is gone. But the reads and sends still report it is valid, and
connected still reports true.
I do this test above in my routine prior to calling the beginreceive (I
figure there is no use beginning a receive if the client hung up), and
before sending data. Doesn't seem to make a difference.

What am I doing wrong?






.



Relevant Pages

  • [PATCH 0/5] [RFC] AF_RXRPC socket family implementation [try #3]
    ... These patches together supply secure client-side RxRPC connectivity as a Linux ... kernel socket family. ... presentation side is left to the client. ... Each connection goes to a particular "service". ...
    (Linux-Kernel)
  • [PATCH 0/5] [RFC] AF_RXRPC socket family implementation
    ... These patches together supply secure client-side RxRPC connectivity as a Linux ... Make it possible for the client socket to be used to go to more than one ... Each connection goes to a particular "service". ...
    (Linux-Kernel)
  • [PATCH 0/5] [RFC] AF_RXRPC socket family implementation [try #2]
    ... These patches together supply secure client-side RxRPC connectivity as a Linux ... Make it possible for the client socket to be used to go to more than one ... Each connection goes to a particular "service". ...
    (Linux-Kernel)
  • Re: proper way to close a socket?
    ... Am I right that you are basically polling the socket until it either connects or the connection attempt times out? ... You can have a progress bar, you can have a countdown, etc, you can shorten the timeout to 5, 10 seconds, etc! ... The wait block will use selectwhich allows you to detect read, write and error events. ...
    (microsoft.public.vc.mfc)
  • Re: Need some clarification and/or help with java NIO sockets
    ... >> block while the connection is being established. ... >> a limit (connection timeout) to the operation, ... >> I tried calling closeon the socket (since I call connect on the ...
    (comp.lang.java.programmer)