Re: Coping with abnormal network disconections
From: Stanley Feng \(MSFT\) (sfeng_at_microsoft.com)
Date: 02/19/04
- Next message: Stanley Feng \(MSFT\): "Re: WSAEINVAL socket error"
- Previous message: Alan J. McFarlane: "Re: Multiple broadcasts"
- Messages sorted by: [ date ] [ thread ]
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).
-- 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 > >
- Next message: Stanley Feng \(MSFT\): "Re: WSAEINVAL socket error"
- Previous message: Alan J. McFarlane: "Re: Multiple broadcasts"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|