Re: Coping with abnormal network disconections

From: Stanley Feng \(MSFT\) (sfeng_at_microsoft.com)
Date: 02/19/04


Date: Wed, 18 Feb 2004 17:27:16 -0800

1. Your logical below is the recommended way of gracefully close a socket on
both directions - but it has a caveat - you need to call recev until you get
a FD_CLOSE event (not until you have no data to receive), FD_CLOSE event is
signaled to you when an incoming FIN is received from remote peer. After
this point, you can proceed to closesocket().

2. However, gracefully closing a socket may conflict with your goal of
exiting the thread or abort the connection rapidly. The way to achieve your
goal may be just abort the connection. Refer to MSDN closesocket() API for
details on how to abort a connection.(SO_LINGER, etc).

http://msdn.microsoft.com/library/en-us/winsock/winsock/graceful_shutdown_linger_options_and_socket_closure_2.asp?frame=true

-- 
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples (if any) are subject to the terms specified
at http://www.microsoft.com/info/cpyright.htm"
"Sid Price" <noname@noname.com> wrote in message
news:%23Mwjntj2DHA.208@TK2MSFTNGP12.phx.gbl...
> I am working on a project that has a number of devices that are
> interconnected with data paths (not part of the network). The control of
> these devices is done using TCP/IP in a peer to peer fashion. For each
peer
> to peer connection each device is running a separate thread. If one of the
> devices fails then the peers that have direct data path connections need
to
> cope with the situation. Also, if one of the devices is unplugged from
> network the connected peers must close the threads servicing the network
> connection to that device. All of this is working fine except that when
the
> devices attempt to close the threads after another device has been
unplugged
> form the network the threads take a very long time to exit.
>
> I am using the recommended close procedure for my winsock threads :
>
>  shutdown(MyData->sConnection,SD_SEND) ;
>  //
>  // Call recv until no more data is returned
>  //
>  {
>      int iResult ;
>
>       while(1)
>       {
>            iResult =
recv(MyData->sConnection,&bBuffer[0],sizeof(bBuffer),0)
> ;
>            if((iResult == 0) || (iResult == SOCKET_ERROR))
>            {
>                 break;
>            }
>       }
>  }
>  closesocket (MyData->sConnection);
>
> Is there some other way to force the connection closed and avoid the very
> long delays? I have found that I get an exception if I do not use the call
> to recv as show.
>
> Thanks
> Sid.
>
> -- 
> Sid Price's Software Tools
> Tools for Embedded Systems Development
> http://www.softtools.com
>
>


Relevant Pages

  • New to SBS 2003 and really struggling
    ... SBS 2003 having always had Peer to Peer networks. ... I decided to upgrade our peer to peer network to SBS 2003 with I have to say ... broadband connection via an ADSL modem. ... Ethernet to the server. ...
    (microsoft.public.windows.server.sbs)
  • Re: Wireless networking-The computers cant see each other
    ... Peer to peer has nothing to do with using a router. ... I clearly indicated that it is a peer to peer network (i.e. no ... Each system reports that the connection is up and I can ...
    (microsoft.public.windowsxp.general)
  • ics through dial up on network-win2000+win98se (AOL)
    ... I have network which is running 'a OK' and am awaiting ... Internet Connection Sharing through the dial up computer ... There are three computers in total, peer to peer runs fine ...
    (microsoft.public.win2000.networking)
  • Re: New to SBS 2003 and really struggling
    ... > SBS 2003 having always had Peer to Peer networks. ... > I decided to upgrade our peer to peer network to SBS 2003 with I have to ... > broadband connection via an ADSL modem. ... > Ethernet to the server. ...
    (microsoft.public.windows.server.sbs)
  • RE: Problems with Permissions
    ... And SBS server is only take ... the role of an internal server. ... they are all configured to connected to internal network. ... g. Run the Configure Email and Internet Connection Wizard on SBS server. ...
    (microsoft.public.windows.server.sbs)