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]

Re: [PATCH] ada/35953: Guard against empty buffers and end-of-connection


* Samuel Tardieu <sam@rfc1149.net> [2008-12-01 17:05:15 +0100]

| * Thomas Quinot <quinot@adacore.com> [2008-11-28 16:06:58 +0100]
| 
| | * Samuel Tardieu, 2008-04-17 :
| | 
| | > ada/35953: Guard against empty buffers and end-of-connection
| | 
| | Reviving this old discussion...
| [...]
| | Furthermore this patch seems to be against some version of g-socket.adb
| | that does not correpond to what currently is in the FSF repository.
| 
| You must be kidding, right? It is against the version of 2008-04-17, which
| was current when I sent the mail :)

Oh, and it was mentionned in the origin patch that it was to be applied
after the one for PR ada/9535: Do not loop when writing/reading on datagram
socket.

That may explain the discrepancies.

For reference, here is the patch I am talking about:


Author: Samuel Tardieu <sam@rfc1149.net>
Date:   Mon Dec 1 17:29:13 2008 +0100

    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.

diff --git a/gcc/ada/g-socket.adb b/gcc/ada/g-socket.adb
index 0906aec..6d61705 100644
--- a/gcc/ada/g-socket.adb
+++ b/gcc/ada/g-socket.adb
@@ -1496,27 +1496,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;
 
    ----------
@@ -2267,27 +2252,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;


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