Browse Source

* Negative time value waits forever

Michaël Van Canneyt 4 years ago
parent
commit
72213d42da
1 changed files with 10 additions and 3 deletions
  1. 10 3
      packages/fcl-net/src/ssockets.pp

+ 10 - 3
packages/fcl-net/src/ssockets.pp

@@ -353,6 +353,7 @@ var
   FDSR,FDSW,FDSE : TFDSet;
   FDSR,FDSW,FDSE : TFDSet;
   PFDSR,PFDSW,PFDSE : PFDSet;
   PFDSR,PFDSW,PFDSE : PFDSet;
   TimeV: TTimeVal;
   TimeV: TTimeVal;
+  PTV : ^TTimeVal;
   res : Longint;
   res : Longint;
 
 
   Procedure DoSet(var FDS : TFDSet; var PFDS : PFDSet; aState : TSocketState);
   Procedure DoSet(var FDS : TFDSet; var PFDS : PFDSet; aState : TSocketState);
@@ -397,14 +398,20 @@ begin
   Result:=[];
   Result:=[];
 {$if defined(unix) or defined(windows)}
 {$if defined(unix) or defined(windows)}
   Res:=-1;
   Res:=-1;
-  TimeV.tv_usec := (TimeOut mod 1000) * 1000;
-  TimeV.tv_sec := TimeOut div 1000;
+  if Timeout<0 then
+    PTV:=Nil
+  else
+    begin
+    TimeV.tv_usec := (TimeOut mod 1000) * 1000;
+    TimeV.tv_sec := TimeOut div 1000;
+    PTV:=@TimeV;
+    end;
   DoSet(FDSR,PFDSR,sosCanRead);
   DoSet(FDSR,PFDSR,sosCanRead);
   DoSet(FDSW,PFDSW,sosCanWrite);
   DoSet(FDSW,PFDSW,sosCanWrite);
   DoSet(FDSE,PFDSE,sosException);
   DoSet(FDSE,PFDSE,sosException);
 {$endif}
 {$endif}
 {$ifdef unix}
 {$ifdef unix}
-  Res:=fpSelect(Socket.Handle + 1, PFDSR, PFDSW, PFDSE, @TimeV);
+  Res:=fpSelect(Socket.Handle + 1, PFDSR, PFDSW, PFDSE, PTV);
 {$endif}
 {$endif}
 {$ifdef windows}
 {$ifdef windows}
   Res:=winsock2.Select(Socket.Handle + 1, PFDSR, PFDSW, PFDSE, @TimeV);
   Res:=winsock2.Select(Socket.Handle + 1, PFDSR, PFDSW, PFDSE, @TimeV);