fcl-net: ssockets are not properly closed on Windows with CloseSocket
<h3><details><summary>Original Reporter info from Mantis: <small>uaply</small></summary><small> - **Reporter name:** </small></details></h3> ## Description: Sockets are not properly closed on Windows, because procedures in `ssockets.pas` use `FileClose()` instead of `CloseSocket()`.<br/> The result is Windows eventually runs out of internal resources. Relevant code:<br/> <pre> destructor TSocketStream.Destroy; begin if FSocketInitialized then {$ifdef netware} CloseSocket(Handle); &LtPos;-- it should be run for Windows too {$else} FileClose(Handle); {$endif} inherited Destroy; end; </pre> <pre> Procedure TSocketServer.Close; begin If FSocket&LtPos;>-1 Then {$ifdef netware} CloseSocket(FSocket); &LtPos;-- it should be run for Windows too {$else} FileClose(FSocket); {$endif} FSocket:=-1; end; </pre> ## Steps to reproduce: Run anything such simple as <br/> <pre> program testhttp; uses SysUtils, fphttpapp; begin Application.Initialize; Application.Port:=8080; Application.Threaded:=True; Application.Run; end. </pre> Then attack it with Apache benchmarking tool:<br/> <pre>ab.exe -c 10 -n 40000 -r http://127.0.0.1:8080/</pre> On my Windows XP SP3 (32-bit) the program constantly fails roughly after 32000 requests with <pre> Exception at 0042EE09: ESocketError: Could not accept a client connection on socket: 1924, error 10055. </pre> ## Additional information: Modifying conditionals to run CloseSockets() instead FileClose() of fixed this case for me. See also same-looking bugs in other projects:<br/> http://microsoft.public.win32.programmer.networks.narkive.com/EoNck2gO/does-closesocket-call-closehandle-internally https://codereview.appspot.com/3834042/ ## Mantis conversion info: - **Mantis ID:** 24802 - **OS:** Windows XP - **OS Build:** SP3 - **Platform:** win32 - **Version:** 2.7.1 - **Fixed in version:** 2.6.4 - **Fixed in revision:** 25472 (#70753db803caff6e27e205da007c4f68e433ed2e) - **Monitored by:** » @xhajt03 (Tomas Hajny)
issue