diff mbox series

[Ada] Timeout correction on Get_Socket_Option

Message ID 20210707162509.GA2543017@adacore.com
State New
Headers show
Series [Ada] Timeout correction on Get_Socket_Option | expand

Commit Message

Pierre-Marie de Rodat July 7, 2021, 4:25 p.m. UTC
The Set_Socket_Option shifts timeout for -500ms on old Windows versions,
but Get_Socket_Option did +500ms for timeouts on all Windows versions.
This commit fixes it and +500ms on Get_Socket_Option only for old
Windows versions.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

	* libgnat/g-socket.adb (Get_Socket_Option): Add 500ms only when
	Minus_500ms_Windows_Timeout is True.
	(Set_Socket_Option): Use "* 1000" instead of "/ 0.001" to
	convert to milliseconds.
diff mbox series

Patch

diff --git a/gcc/ada/libgnat/g-socket.adb b/gcc/ada/libgnat/g-socket.adb
--- a/gcc/ada/libgnat/g-socket.adb
+++ b/gcc/ada/libgnat/g-socket.adb
@@ -1570,14 +1570,18 @@  package body GNAT.Sockets is
             | Send_Timeout
          =>
             if Is_Windows then
-
-               --  Timeout is in milliseconds, actual value is 500 ms +
-               --  returned value (unless it is 0).
-
                if U4 = 0 then
                   Opt.Timeout := 0.0;
+
                else
-                  Opt.Timeout :=  Duration (U4) / 1000 + 0.500;
+                  if Minus_500ms_Windows_Timeout then
+                     --  Timeout is in milliseconds, actual value is 500 ms +
+                     --  returned value (unless it is 0).
+
+                     U4 := U4 + 500;
+                  end if;
+
+                  Opt.Timeout := Duration (U4) / 1000;
                end if;
 
             else
@@ -2724,7 +2728,7 @@  package body GNAT.Sockets is
                Len := U4'Size / 8;
                Add := U4'Address;
 
-               U4 := C.unsigned (Option.Timeout / 0.001);
+               U4 := C.unsigned (Option.Timeout * 1000);
 
                if Option.Timeout > 0.0 and then U4 = 0 then
                   --  Avoid round to zero. Zero timeout mean unlimited