Good morning to all, I have done some investigations and noticed one interesting thing: the error appears only when the socket handle is equal to previous. Here's the log:
(SetState is my procedure to change client's state, and I also added to TWSocket code two log writes: "TCustomWSocket.Connected" + FHSocket, it is written after WSocket_Synchronized_socket call in TCustomWSocket.Connect, and "TCustomWSocket.Closed" + FHSocket, it is written after FCloseInvoked := TRUE; TriggerSessionClosed(Error); in TCustomWSocket.InternalClose. 2010-04-21 18:33:49 SetState: csSleeping -> csConnecting 2010-04-21 18:33:49 TCustomWSocket.Connected 1112 2010-04-21 18:33:49 SocketChangeState, wsClosed -> wsOpened 2010-04-21 18:33:49 TWSocket will connect to **** 2010-04-21 18:33:49 SocketChangeState, wsOpened -> wsConnecting 2010-04-21 18:34:00 Connection timeout 2010-04-21 18:34:00 SetState: csConnecting -> csTimeout 2010-04-21 18:34:00 SetState: csTimeout -> csReconnect 2010-04-21 18:34:00 SetState: csReconnect -> csCloseNow 2010-04-21 18:34:00 00D384D0 TCustomWSocket.Shutdown 1 1112 2010-04-21 18:34:00 SocketChangeState, wsConnecting -> wsClosed 2010-04-21 18:34:00 SocketSessionClosed 2010-04-21 18:34:00 TCustomWSocket.Closed -1 2010-04-21 18:34:00 Try to connect: (attempt 2 of 3) 2010-04-21 18:34:00 SetState: csReconnect -> csConnecting 2010-04-21 18:34:00 TCustomWSocket.Connected 1112 2010-04-21 18:34:00 SocketChangeState, wsClosed -> wsOpened 2010-04-21 18:34:00 TWSocket will connect to **** 2010-04-21 18:34:00 SocketChangeState, wsOpened -> wsConnecting 2010-04-21 18:34:00 SocketChangeState, wsConnecting -> wsConnected 2010-04-21 18:34:00 SocketSessionConnected, Socket operation on non-socket (#10038) 2010-04-21 18:34:00 00D384D0 TCustomWSocket.Shutdown 1 1112 2010-04-21 18:34:00 SocketChangeState, wsConnected -> wsClosed 2010-04-21 18:34:00 SocketSessionClosed 2010-04-21 18:34:00 TCustomWSocket.Closed -1 As you can see, socket is closed and handle cleared properly. But - the newly assigned handle is the same as previous. I suspect the error to happen because of half-open or a kind of "under-closed" socket: i.e. the one which isn't completely closed, but the OS considers it's handle to be free. Having read MSDN about closesocket() (http://msdn.microsoft.com/en-us/library/ms737582(VS.85).aspx), I guess that the reason is Linger options. But I have default values: FLingerOnOff := wsLingerOn; FLingerTimeout := 0, and MSDN says it is "Hard" type of close with no waiting. So what's the right and proper way to reconnect a socket? Should I start reconnecting only from SocketSessionClosed? -- Anton -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be