From: Dmitriy Anisimkov Date: Tue, 18 May 2021 05:03:31 +0000 (+0600) Subject: [Ada] Add socket options to control keepalive on TCP connection X-Git-Tag: basepoints/gcc-13~6208 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f3ff72939e52a381d28f3c4879f2eaa1d154ff73;p=thirdparty%2Fgcc.git [Ada] Add socket options to control keepalive on TCP connection gcc/ada/ * libgnat/g-socket.ads (Option_Name): Add Keep_Alive_Count, Keep_Alive_Idle, and Keep_Alive_Interval items to enumeration. (Option_Type): Add Keep_Alive_Count, Keep_Alive_Idle, and Keep_Alive_Interval alternatives to the case of discriminated record. * libgnat/g-socket.adb (Options): Add Keep_Alive_Count, Keep_Alive_Idle, and Keep_Alive_Interval to items enumerator to OS constant converter. (Set_Socket_Option): Process Keep_Alive_Count, Keep_Alive_Idle, and Keep_Alive_Interval socket options. (Get_Socket_Option): Idem. --- diff --git a/gcc/ada/libgnat/g-socket.adb b/gcc/ada/libgnat/g-socket.adb index ec4cf29d42fe..a246303cb66c 100644 --- a/gcc/ada/libgnat/g-socket.adb +++ b/gcc/ada/libgnat/g-socket.adb @@ -96,6 +96,9 @@ package body GNAT.Sockets is Options : constant array (Specific_Option_Name) of C.int := (Keep_Alive => SOSC.SO_KEEPALIVE, + Keep_Alive_Count => SOSC.TCP_KEEPCNT, + Keep_Alive_Idle => SOSC.TCP_KEEPIDLE, + Keep_Alive_Interval => SOSC.TCP_KEEPINTVL, Reuse_Address => SOSC.SO_REUSEADDR, Broadcast => SOSC.SO_BROADCAST, Send_Buffer => SOSC.SO_SNDBUF, @@ -1442,6 +1445,9 @@ package body GNAT.Sockets is | Error | Generic_Option | Keep_Alive + | Keep_Alive_Count + | Keep_Alive_Idle + | Keep_Alive_Interval | Multicast_If_V4 | Multicast_If_V6 | Multicast_Loop_V4 @@ -1511,6 +1517,15 @@ package body GNAT.Sockets is => Opt.Enabled := (V4 /= 0); + when Keep_Alive_Count => + Opt.Count := Natural (V4); + + when Keep_Alive_Idle => + Opt.Idle_Seconds := Natural (V4); + + when Keep_Alive_Interval => + Opt.Interval_Seconds := Natural (V4); + when Busy_Polling => Opt.Microseconds := Natural (V4); @@ -2620,6 +2635,21 @@ package body GNAT.Sockets is Len := V4'Size / 8; Add := V4'Address; + when Keep_Alive_Count => + V4 := C.int (Option.Count); + Len := V4'Size / 8; + Add := V4'Address; + + when Keep_Alive_Idle => + V4 := C.int (Option.Idle_Seconds); + Len := V4'Size / 8; + Add := V4'Address; + + when Keep_Alive_Interval => + V4 := C.int (Option.Interval_Seconds); + Len := V4'Size / 8; + Add := V4'Address; + when Busy_Polling => V4 := C.int (Option.Microseconds); Len := V4'Size / 8; diff --git a/gcc/ada/libgnat/g-socket.ads b/gcc/ada/libgnat/g-socket.ads index 03afd3691c28..4372f3eace78 100644 --- a/gcc/ada/libgnat/g-socket.ads +++ b/gcc/ada/libgnat/g-socket.ads @@ -845,11 +845,20 @@ package GNAT.Sockets is -- IP_Protocol_For_TCP_Level -- ------------------------------- - No_Delay, -- TCP_NODELAY + No_Delay, -- TCP_NODELAY -- Disable the Nagle algorithm. This means that output buffer content -- is always sent as soon as possible, even if there is only a small -- amount of data. + Keep_Alive_Count, -- TCP_KEEPCNT + -- Maximum number of keepalive probes + + Keep_Alive_Idle, -- TCP_KEEPIDLE + -- Idle time before TCP starts sending keepalive probes + + Keep_Alive_Interval, -- TCP_KEEPINTVL + -- Time between individual keepalive probes + ------------------------------ -- IP_Protocol_For_IP_Level -- ------------------------------ @@ -923,26 +932,35 @@ package GNAT.Sockets is Enabled : Boolean; case Name is - when Linger => + when Linger => Seconds : Natural; - when others => + when others => null; end case; - when Busy_Polling => + when Keep_Alive_Count => + Count : Natural; + + when Keep_Alive_Idle => + Idle_Seconds : Natural; + + when Keep_Alive_Interval => + Interval_Seconds : Natural; + + when Busy_Polling => Microseconds : Natural; - when Send_Buffer | - Receive_Buffer => + when Send_Buffer | + Receive_Buffer => Size : Natural; - when Error => + when Error => Error : Error_Type; - when Add_Membership_V4 | - Add_Membership_V6 | - Drop_Membership_V4 | - Drop_Membership_V6 => + when Add_Membership_V4 | + Add_Membership_V6 | + Drop_Membership_V4 | + Drop_Membership_V6 => Multicast_Address : Inet_Addr_Type; case Name is when Add_Membership_V4 | @@ -958,13 +976,13 @@ package GNAT.Sockets is when Multicast_If_V6 => Outgoing_If_Index : Natural; - when Multicast_TTL => + when Multicast_TTL => Time_To_Live : Natural; - when Multicast_Hops => + when Multicast_Hops => Hop_Limit : Integer range -1 .. 255; - when Send_Timeout | + when Send_Timeout | Receive_Timeout => Timeout : Timeval_Duration;