Error 10055 bug in TClientSocket?
If you take this simple "program":
procedure TForm1.Timer1Timer(Sender: TObject);
begin
ClientSocket1.Close;
ClientSocket1.Open;
end;
procedure TForm1.ClientSocket1Error(Sender: TObject; Socket:
TCustomWinSocket;
ErrorEvent: TErrorEvent; var ErrorCode: Integer);
begin
ErrorCode:=0;
end;
All it does, is connecting to a non-existing server every second and
ignore all errors. This should work, shouldn't it? But for some reason
you will start getting an error 10055 after about 1 hour (on a win2k
machine). When you run 'netstat -na' on the command prompt you will see
hundreds of sockets open in the LISTEN state. Somehow they don't get
closed after an error. You can't close them yourself, because a call to
TClientSocket.Close is ignored when the socket is not connected (line
1949-1954 in ScktComp.pas):
if (Value <> FClientSocket.Connected) and
not (csDesigning in ComponentState) then
begin
if FClientSocket.Connected then
FClientSocket.Disconnect(FClientSocket.FSocket)
else FClientSocket.Open(FHost, FAddress, FService,
FPort, ClientType = ctBlocking);
end;
FClientSocket.Disconnect frees the socket on the API-level, but it is
never called after an error. The only way to free the socket after an
error is to destroy the entire TClientSocket. To fix this problem, I've
inserted "Disconnect(FSocket);" at line 655 of ScktCompt.pas after the
call to the event handler and it seems to solve the problem, but I don't
know if this has some unwanted side effects. My program seems to work fine.
Is this really a bug in TClientSocket? If so, where can I report it to
Borland?
Emond Papegaaij