Lukas Gebauer wrote:
>> Hi, I have implemented a socket server patterned after the echo
>> example.
>> Everything works fine as long as connection closes ok, but if client
>>
>> cuts the connection short, the server application starts to eat up CPU
>> on the computer.
>
> Are you using latest Synasnap?
>
>
More Info: Lazarus 0.9.2.0/FP 2.04 on XP
I've provided some samples of code below after extracting extraneous code.
Here is the main program file (.lpr). It's a console app.:
var
ClientSock: TTCPBlockSocket;
Sock: TSocket;
Stop: boolean;
begin
// crank up tcp server and start listening for connections
ClientSock := TTCPBlockSocket.Create;
try
ClientSock.CreateSocket;
ClientSock.SetLinger(true, 10);
ClientSock.Bind('0.0.0.0', IntToStr(iPort));
ClientSock.Listen;
while (not Stop) do
begin
if ClientSock.CanRead(5000) then
begin
Sock := ClientSock.Accept;
if (ClientSock.LastError = 0) then
TDTAGIHandler.Create(Sock, '1.2');
end;
end;
finally;
Clientsock.free;
end;
end.
The TDTAGIHandler class is a TThread decendant which creates a
TTCPBlockSocket in it's constructor and assigns the TSocket to its
Socket property. In it's Destructor, I first call CloseSocket and then
free the TTCPBlockSocket.
I have placed breakpoints on both of these methods
(constructor/destructor). If the connection is able to run through and
terminates normally, these methods are called. If the client breaks the
connection mid stride, the destructor is not called and my server eats
up 50% of CPU. If I repeat this a couple more times, my server eats up
99% CPU. Conversely, I can make connection after connection terminating
normally and it behaves wonderfully.
Hope this provides a bit more information to you.
Thanks again for your help.
--
Warm Regards,
Lee
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
synalist-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/synalist-public