summaryrefslogtreecommitdiff
path: root/gcc/ada/g-socket.adb
diff options
context:
space:
mode:
authorcharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2009-07-22 10:39:30 +0000
committercharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2009-07-22 10:39:30 +0000
commit2f1aac99b60b55722a9d79ba7202a84bc5f3cf7e (patch)
treec5a8963e970a6abe500cd73f739c2b706386f685 /gcc/ada/g-socket.adb
parenta67a63e2f256e0ea10297c519be188f09c4a8189 (diff)
downloadgcc-2f1aac99b60b55722a9d79ba7202a84bc5f3cf7e.tar.gz
2009-07-22 Thomas Quinot <quinot@adacore.com>
* sem_util.adb, sem_ch10.adb: Minor reformatting * g-socket.adb (Receive_Socket, recvfrom(2) variant): Apply required special handling for the case of no data received and Item'First = Stream_Element_Offset'First. (Last_Index): New subprogram factoring the above special handling over the various locations where it is required. 2009-07-22 Arnaud Charlet <charlet@adacore.com> * gnat1drv.adb (Gnat1drv): Also disable division by zero and alignment checks in CodePeer_Mode. * gcc-interface/Make-lang.in: Update dependencies. 2009-07-22 Ed Schonberg <schonberg@adacore.com> * sem_aggr.adb: Improve error message. * sem_ch13.adb: If Ignore_Rep_Clauses is enabled, do a minimal analysis of an address representation clause. * freeze.adb (Freeze_Static_Object): An local imported object is legal if it has an address clause. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@149926 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ada/g-socket.adb')
-rw-r--r--gcc/ada/g-socket.adb56
1 files changed, 30 insertions, 26 deletions
diff --git a/gcc/ada/g-socket.adb b/gcc/ada/g-socket.adb
index badebbca599..5685cb54aa6 100644
--- a/gcc/ada/g-socket.adb
+++ b/gcc/ada/g-socket.adb
@@ -119,9 +119,6 @@ package body GNAT.Sockets is
Hex_To_Char : constant String (1 .. 16) := "0123456789ABCDEF";
-- Use to print in hexadecimal format
- function Err_Code_Image (E : Integer) return String;
- -- Return the value of E surrounded with brackets
-
-----------------------
-- Local subprograms --
-----------------------
@@ -253,6 +250,17 @@ package body GNAT.Sockets is
-- during the elaboration and finalization of this package. A single object
-- of this type must exist at library level.
+ function Err_Code_Image (E : Integer) return String;
+ -- Return the value of E surrounded with brackets
+
+ function Last_Index
+ (First : Stream_Element_Offset;
+ Count : C.int) return Stream_Element_Offset;
+ -- Compute the Last OUT parameter for the various Receive_Socket
+ -- subprograms: returns First + Count - 1, except for the case
+ -- where First = Stream_Element_Offset'First and Res = 0, in which
+ -- case Stream_Element_Offset'Last is returned instead.
+
procedure Initialize (X : in out Sockets_Library_Controller);
procedure Finalize (X : in out Sockets_Library_Controller);
@@ -1356,6 +1364,22 @@ package body GNAT.Sockets is
and then Is_Socket_In_Set (Item.Set'Access, C.int (Socket)) /= 0;
end Is_Set;
+ ----------------
+ -- Last_Index --
+ ----------------
+
+ function Last_Index
+ (First : Stream_Element_Offset;
+ Count : C.int) return Stream_Element_Offset
+ is
+ begin
+ if First = Stream_Element_Offset'First and then Count = 0 then
+ return Stream_Element_Offset'Last;
+ else
+ return First + Stream_Element_Offset (Count - 1);
+ end if;
+ end Last_Index;
+
-------------------
-- Listen_Socket --
-------------------
@@ -1581,17 +1605,7 @@ package body GNAT.Sockets is
Raise_Socket_Error (Socket_Errno);
end if;
- if Res = 0
- and then Item'First = Ada.Streams.Stream_Element_Offset'First
- then
- -- No data sent and first index is first Stream_Element_Offset'First
- -- Last is set to Stream_Element_Offset'Last.
-
- Last := Ada.Streams.Stream_Element_Offset'Last;
-
- else
- Last := Item'First + Ada.Streams.Stream_Element_Offset (Res - 1);
- end if;
+ Last := Last_Index (First => Item'First, Count => Res);
end Receive_Socket;
--------------------
@@ -1623,7 +1637,7 @@ package body GNAT.Sockets is
Raise_Socket_Error (Socket_Errno);
end if;
- Last := Item'First + Ada.Streams.Stream_Element_Offset (Res - 1);
+ Last := Last_Index (First => Item'First, Count => Res);
To_Inet_Addr (Sin.Sin_Addr, From.Addr);
From.Port := Port_Type (Network_To_Short (Sin.Sin_Port));
@@ -1863,17 +1877,7 @@ package body GNAT.Sockets is
Raise_Socket_Error (Socket_Errno);
end if;
- if Res = 0
- and then Item'First = Ada.Streams.Stream_Element_Offset'First
- then
- -- No data sent and first index is first Stream_Element_Offset'First
- -- Last is set to Stream_Element_Offset'Last.
-
- Last := Ada.Streams.Stream_Element_Offset'Last;
-
- else
- Last := Item'First + Ada.Streams.Stream_Element_Offset (Res - 1);
- end if;
+ Last := Last_Index (First => Item'First, Count => Res);
end Send_Socket;
-----------------