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

Laurent GUERBY laurent@guerby.net
Wed Apr 16 06:50:00 GMT 2008


On Wed, 2008-04-16 at 01:20 +0200, Samuel Tardieu wrote:
> @@ -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;


IIRC the data payload of an UDP datagram can be zero (to be checked I
might be wrong), in this case Send_Socket will set Last to Item'First
and the "if" above will erroneously raise Socket_Error because Last =
Item'First /= Item'Last by construction of empty array bounds in Ada.

Might be a thing to try out as there might be similar handling
of zero elsewhere.

Laurent




More information about the Gcc-patches mailing list