[SOLVED] Improvement of function TSocketServer.RunIdleLoop lazarus / 64-FPC development ---------------------------------------------------------------------- lagprogramming · 2023-07-15 08:46 packages/fcl-net/src/ssockets.pp has the following function: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function TSocketServer.RunIdleLoop: Boolean; // Run Accept idle loop. Return True if there is a new connection waiting{$if defined(unix) or defined(windows)}var  FDS: TFDSet;  TimeV: TTimeVal;{$endif}begin  Repeat    Result:=False;{$if defined(unix) or defined(windows)}    TimeV.tv_usec := (AcceptIdleTimeout mod 1000) * 1000;    TimeV.tv_sec := AcceptIdleTimeout div 1000;{$endif}{$ifdef unix}    FDS := Default(TFDSet);    fpFD_Zero(FDS);    fpFD_Set(FSocket, FDS);    Result := fpSelect(FSocket + 1, @FDS, @FDS, @FDS, @TimeV) > 0;{$else}{$ifdef windows}    FDS := Default(TFDSet);    FD_Zero(FDS);    FD_Set(FSocket, FDS);    Result := winsock2.Select(FSocket + 1, @FDS, @FDS, @FDS, @TimeV) > 0;{$endif}{$endif}    If not Result then    DoOnIdle;  Until Result or (Not FAccepting);end;The repeat loop contains an unnecessary conditional jump. The patch at the end of the post changes Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i If not Result then  DoOnIdle;Until Result or (Not FAccepting);with Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i If Result then  break;DoOnIdle;Until (Not FAccepting); Here is the patch Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i diff --git a/packages/fcl-net/src/ssockets.pp b/packages/fcl- net/src/ssockets.ppindex 755af6d8bf..26da36d7fa 100644--- a/packages/fcl-net/src/ssockets.pp+++ b/packages/fcl- net/src/ssockets.pp@@ -928,9 +928,10 @@ function TSocketServer.RunIdleLoop: Boolean;     Result := winsock2.Select(FSocket + 1, @FDS, @FDS, @FDS, @TimeV) > 0; {$endif} {$endif}-    If not Result then-      DoOnIdle;-  Until Result or (Not FAccepting);+    If Result then+      break;+    DoOnIdle;+  Until (Not FAccepting); end;  procedure TSocketServer.Listen; ---------------------------------------------------------------------- bytebites · 2023-07-15 17:21 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Until (Not FAccepting); Unnecessary (). ---------------------------------------------------------------------- runewalsh · 2023-07-15 17:31 Also Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$ifdef unix}    FDS := Default(TFDSet);    fpFD_Zero(FDS);    fpFD_Set(FSocket, FDS);    Result := fpSelect(FSocket + 1, @FDS, @FDS, @FDS, @TimeV) > 0;{$else}{$ifdef windows}    FDS := Default(TFDSet);  FD_Zero(FDS);    FD_Set(FSocket, FDS);    Result := winsock2.Select(FSocket + 1, @FDS, @FDS, @FDS, @TimeV) > 0;{$endif}{$endif}⇓ Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$ifdef unix}    FDS := Default(TFDSet);    fpFD_Zero(FDS);    fpFD_Set(FSocket, FDS);    Result := fpSelect(FSocket + 1, @FDS, @FDS, @FDS, @TimeV) > 0;{$elseif defined(windows)}    FDS := Default(TFDSet);    FD_Zero(FDS);    FD_Set(FSocket, FDS);    Result := winsock2.Select(FSocket + 1, @FDS, @FDS, @FDS, @TimeV) > 0;{$endif} ---------------------------------------------------------------------- Josh · 2023-07-16 09:10 maybe Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function TSocketServer.RunIdleLoop: Boolean;// Run Accept idle loop. Return True if there is a new connection waiting{$if defined(unix) or defined(windows)}var  FDS: TFDSet;  TimeV: TTimeVal;{$endif}begin  Repeat    Result:=False;    {$if defined(unix) or defined(windows)}  TimeV.tv_usec := (AcceptIdleTimeout mod 1000) * 1000;    TimeV.tv_sec := AcceptIdleTimeout div 1000;    FDS := Default(TFDSet);    {$ifdef unix}    fpFD_Zero(FDS);    fpFD_Set(FSocket, FDS);    Result := fpSelect(FSocket + 1, @FDS, @FDS, @FDS, @TimeV) > 0;    {$else}    FD_Zero(FDS);    FD_Set(FSocket, FDS);    Result := winsock2.Select(FSocket + 1, @FDS, @FDS, @FDS, @TimeV) > 0;    {$endif}    {$endif}    If Result then break;    DoOnIdle;  Until (Not FAccepting);end; ---------------------------------------------------------------------- AlexTP · 2023-07-16 10:08 Posted to https://gitlab.com/freepascal.org/fpc/source/-/issues/40351