Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Mar : Re: Socket Error # 0

www.cryer.info
Managed Newsgroup Archive

Re: Socket Error # 0

Subject:Re: Socket Error # 0
Posted by:"Stephan Jaschke" (ne..@stj-software.de)
Date:Fri, 23 Mar 2007 09:44:42

Remy Lebeau (TeamB) schrieb:
>> Your call stack is incomplete.  TIdTCPConnection.WriteBuffer() does
>> not directly call TIdStack.RaiseSocketError().  There where is all
> of the
>> calls in between for either TIdStack.CheckForSocketError() or
>> TIdStack.RaiseSocketError()?
>
> Ignore that.  WriteBuffer() does directly call RaiseSocketError(), but
> only if CheckForSocketError() returned True:
>
>     // Check to see if the error signifies disconnection
>     if GStack.CheckForSocketError(nByteCount, [ID_WSAESHUTDOWN,
> Id_WSAECONNABORTED, Id_WSAECONNRESET]) then begin
>         DisconnectSocket;
>         GStack.RaiseSocketError(GStack.LastError);
>     end;
>
> If Send() had returned SOCKET_ERROR, then only way that
> CheckForSocketError() could return True is if WSAGetLastError()
> returned WSAESHUTDOWN, WSAECONNABORTED, or WSAECONNRESET.  Anything
> else would result in a exception being thrown by CheckForSocketError()
> instead of WriteBuffer(), and the ErrorCode would not be 0.  Since
> CheckForSocketError() is the only method that sets the
> GStack.LastError property, what you describe suggests that
> DisconnectSocket() is resetting the LastError back to 0 before
> RaiseSocketError() is called, which is impossible as
> DisconnectSocket() never calls CheckForSocketError().

Hm. So far so "good".
Let see or try to figure out:

- Send() had returned SOCKET_ERROR
- WSAGetLastError() returned
   WSAESHUTDOWN, WSAECONNABORTED, or WSAECONNRESET
   as the CheckForSocketError must have returned True according the
   call stack (which is complete)

In my version (original Delphi 7.0, Indy 9.00.10) the code is

// Check to see if the error signifies disconnection
if GStack.CheckForSocketError(
      nByteCount,[ID_WSAESHUTDOWN, Id_WSAECONNABORTED,
Id_WSAECONNRESET]) then begin
   DisconnectSocket;
   GStack.RaiseSocketError(GStack.WSGetLastError);
end;

... and the diffrence is the call to GStack.WSGetLastError in my version
which implicit calls WSAGetLastError and gives obviously _not_ LastError
but 0 as no other winsock-call was involved.
So in this situation (in version 9.00.10) the original error code is
lost. The code must be one of the above mentioned (ID_WSAESHUTDOWN,
Id_WSAECONNABORTED, Id_WSAECONNRESET) so I should investigate further
what might cause them.

Did I get it right?

> On the other hand, WriteBuffer() does call CheckForDisconnect() before
> calling CheckForSocketError().  Perhaps CheckForDisconnect() is
> accessing the socket, indirectly resetting WSAGastLastError() back to
> 0.  That would then cause CheckForSocketError() to throw an exception
> with an ErrorCode of 0.  But then, CheckForSocketError() should have
> appeared in your call stack in that situation.

... and it didn't.

Stephan
--
Logik ist die Kunst, zuversichtlich in die Irre zu gehen.

Stephan Jaschke - EDV-Beratung und Softwareentwicklung
Mail: support@stj-software.de - ICQ: 361511624

Replies:

In response to:

www.cryer.info
Managed Newsgroup Archive