Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Sep : Re: Indy 9 - not detecting disconnect over VPN
| Subject: | Re: Indy 9 - not detecting disconnect over VPN |
| Posted by: | "Remy Lebeau (TeamB)" (no.spam@no.spam.com) |
| Date: | Wed, 19 Sep 2007 11:15:50 |
<user@domain.invalid> wrote in message
news:46f13a4a@newsgroups.borland.com...
> I have a client/server application that connects over a VPN.
> When the connection goes away, the writer to the socket
> detects the disconnect, but the reader of the socket continues
> to wait for data.
Either the reader is not checking for a disconnect properly (which is not
likely since you are using Indy, which does such checks internally), or the
OS is not reporting the disconnect to begin with.
> I created a sample application that shows this behavior and can
> provide it (if you tell me where to do so)
Just show the relevant code here. If it is large, then post to the
.attachments newsgroup instead.
> for i := 1 to count do
> s := s+Client.ReadChar;
That is very inefficient. Since you know the length of the string ahead of
time, use ReadString() instead:
s := Client.ReadString(count);
> if not Win32Check(PostThreadMessage(mainThreadID,
> GUI_MESSAGE_FROM_THREAD,
> GMFT_CLIENT_CHANGE_CONNECTION_INFO,
> LParam(infoRec))) then
Win32Check() raises an exception if an error occurs. In order to dispose of
your memory correctly, you need to wrap it in an exception handler:
try
Win32Check(PostThreadMessage(...));
except
Dispose(infoRec);
end;
Otherwise, get rid of Win32Check() and use PostThreadMessage()'s return
value directly instead:
if not PostThreadMessage(...) then
Dispose(infoRec);
Gambit