This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] ada/35953: Guard against empty buffers and end-of-connection
- From: Samuel Tardieu <sam at rfc1149 dot net>
- To: Thomas Quinot <quinot at adacore dot com>
- Cc: Arnaud Charlet <charlet at adacore dot com>, gcc-patches at gcc dot gnu dot org
- Date: Mon, 1 Dec 2008 17:32:24 +0100
- Subject: Re: [PATCH] ada/35953: Guard against empty buffers and end-of-connection
- References: <20080416162528.3625.35938.stgit@dawn.rfc1149.net> <20080417095354.GA41254@adacore.com> <2008-04-17-12-23-48+trackit+sam@rfc1149.net> <20080417104000.GB73896@melamine.cuivre.fr.eu.org> <2008-04-17-12-48-19+trackit+sam@rfc1149.net> <20080417105146.GA76360@melamine.cuivre.fr.eu.org> <2008-04-17-13-39-32+trackit+sam@rfc1149.net> <20081128150658.GB78410@melamine.cuivre.fr.eu.org> <2008-12-01-17-05-15+trackit+sam@rfc1149.net>
* 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;