This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] ada/9535: Do not loop when writing/reading on datagram socket


It makes little sense to chop an outgoing packet into several datagrams
as they are not guaranteed to arrive in the same order if they arrive
at all. For the same reason, it makes little sense to aggregate incoming
packets as they may arrive at random.

While the looping semantics is fine with streams, it doesn't work for
datagrams, and noone expects it to work.

This patch removes the useless loops. As a side effect, it will also warn
the user as expected if one tries to send a packet longer than the length
allowed in one datagram.

    gcc/ada/
	PR ada/9535
	* g-socket.adb (Read, Write): Remove loop for datagram sockets.
---
 gcc/ada/g-socket.adb |   50 ++++++++++++--------------------------------------
 1 files changed, 12 insertions(+), 38 deletions(-)

diff --git a/gcc/ada/g-socket.adb b/gcc/ada/g-socket.adb
index 016b3ff..9ee9877 100644
--- a/gcc/ada/g-socket.adb
+++ b/gcc/ada/g-socket.adb
@@ -1347,27 +1347,12 @@ package body GNAT.Sockets is
       Item   : out Ada.Streams.Stream_Element_Array;
       Last   : out Ada.Streams.Stream_Element_Offset)
    is
-      First : Ada.Streams.Stream_Element_Offset          := Item'First;
-      Index : Ada.Streams.Stream_Element_Offset          := First - 1;
-      Max   : constant Ada.Streams.Stream_Element_Offset := Item'Last;
-
    begin
-      loop
-         Receive_Socket
-           (Stream.Socket,
-            Item (First .. Max),
-            Index,
-            Stream.From);
-
-         Last := Index;
-
-         --  Exit when all or zero data received. Zero means that the socket
-         --  peer is closed.
-
-         exit when Index < First or else Index = Max;
-
-         First := Index + 1;
-      end loop;
+      Receive_Socket
+        (Stream.Socket,
+         Item,
+         Last,
+         Stream.From);
    end Read;
 
    ----------
@@ -2119,27 +2104,16 @@ package body GNAT.Sockets is
    is
       pragma Warnings (Off, Stream);
 
-      First : Ada.Streams.Stream_Element_Offset          := Item'First;
-      Index : Ada.Streams.Stream_Element_Offset          := First - 1;
-      Max   : constant Ada.Streams.Stream_Element_Offset := Item'Last;
+      Last : Ada.Streams.Stream_Element_Offset;
 
    begin
-      loop
-         Send_Socket
-           (Stream.Socket,
-            Item (First .. Max),
-            Index,
-            Stream.To);
-
-         --  Exit when all or zero data sent. Zero means that the socket has
-         --  been closed by peer.
+      Send_Socket
+        (Stream.Socket,
+         Item,
+         Last,
+         Stream.To);
 
-         exit when Index < First or else Index = Max;
-
-         First := Index + 1;
-      end loop;
-
-      if Index /= Max then
+      if Last /= Item'Last then
          raise Socket_Error;
       end if;
    end Write;
-- 
1.5.5.234.g5042


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]