Addition of Null_Socket_FD in sockets.ads

Oliver Kellogg <[email protected]> Fri, 12 Mar 2010 16:33:43 +0100
Newsgroups gmane.comp.lang.ada.sockets
Organization EADS Deutschland GmbH
Message-ID <[email protected]>
--Boundary-00=_X7lmLhaoOTZG6mQ
Content-Type: text/plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hi,

I found the Null_Socket_FD useful for checking whether a Socket_FD has a 
usable value, in the sytle of

   if My_Socket /= Sockets.Null_Socket_FD then
      -- now we know that My_Socket is usable
   end if;

Further, I found that "make clean" does not remove the b~* files created by 
gnatbind so I added that to the clean rule.

One observation: "make clean" in doc/ removes the *.texi files - is that 
intentional?

Thanks for AdaSockets,

 Oliver


-- 
Oliver M. Kellogg
EADS Deutschland GmbH
Defence and Communication Systems
Dept. ISEG42
89077 Ulm
Tel: +49 (0) 731.392-7138
E-Fax: +49 (0) 731.392-20 7138
E-Mail: [email protected]

EADS Deutschland GmbH
Registered Office: Ottobrunn
District Court of Munich HRB107648
Chairman of the Supervisory Board: Dr. Thomas Enders
Managing Directors: Dr. Stefan Zoller (chairman), Michael Hecht



--Boundary-00=_X7lmLhaoOTZG6mQ
Content-Type: text/x-patch; charset="iso-8859-1"; name="adasocktets-1.8.7.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="adasocktets-1.8.7.diff"

Index: src/sockets.ads
===================================================================
--- src/sockets.ads	(revision 1616)
+++ src/sockets.ads	(working copy)
@@ -44,6 +44,9 @@
    type Socket_FD is tagged private;
    --  A socket
 
+   Null_Socket_FD : constant Socket_FD;
+   --  An empty socket
+
    type Socket_Domain is (PF_INET, AF_INET);
    --  PF_INET: Internet sockets
    --  AF_INET: This entry is bogus and should never be used, but it is
@@ -226,9 +229,14 @@
    type Shutdown_Array is array (Receive .. Send) of Boolean;
 
    type Socket_FD is tagged record
-      FD       : Interfaces.C.int;
-      Shutdown : Shutdown_Array;
+      FD       : Interfaces.C.int := Interfaces.C."-" (1);
+      Shutdown : Shutdown_Array := (others => False);
       Buffer   : Buffer_Access;
    end record;
 
+   Null_Socket_FD : constant Socket_FD :=
+     (FD => Interfaces.C."-" (1),
+      Shutdown => (others => False),
+      Buffer => null);
+
 end Sockets;
Index: src/Makefile.in
===================================================================
--- src/Makefile.in	(revision 1616)
+++ src/Makefile.in	(working copy)
@@ -252,7 +252,7 @@
 
 ALIS = $(ADA_OBJECTS:.o=.ali) $(ADA_OBJECTS_WIN:.o=.ali)
 ADACOMPILER = $(top_srcdir)/support/adacompiler
-CLEANFILES = *.o *.ali
+CLEANFILES = *.o *.ali b~*
 DISTCLEANFILES = b_split.c split constants_nodef \
 		sockets-thin.ads sockets-thin.adb
 
Index: src/sockets-multicast.ads
===================================================================
--- src/sockets-multicast.ads	(revision 1616)
+++ src/sockets-multicast.ads	(working copy)
@@ -46,6 +46,8 @@
 
    type Multicast_Socket_FD is new Socket_FD with private;
 
+   Null_Multicast_Socket_FD : constant Multicast_Socket_FD;
+
    function Create_Multicast_Socket
      (Group     : String;
       Port      : Positive;
@@ -83,4 +85,8 @@
       Target : Sockets.Types.Sockaddr_In;
    end record;
 
+   Null_Multicast_Socket_FD : constant Multicast_Socket_FD :=
+     (Sockets.Null_Socket_FD with
+      Target => Sockets.Types.Null_Sockaddr_In);
+
 end Sockets.Multicast;
Index: src/sockets-types.ads.in
===================================================================
--- src/sockets-types.ads.in	(revision 1616)
+++ src/sockets-types.ads.in	(working copy)
@@ -70,8 +70,8 @@
 
    type Sockaddr_In is record
 @SA_LEN@      Sin_Len    : C.unsigned_char := 18;
-@SA_LEN@      Sin_Family : C.unsigned_char;
-@NO_SA_LEN@      Sin_Family : C.unsigned_short;
+@SA_LEN@      Sin_Family : C.unsigned_char := 0;
+@NO_SA_LEN@      Sin_Family : C.unsigned_short := 0;
       Sin_Port   : C.unsigned_short      := 0;
       Sin_Addr   : In_Addr               := Inaddr_Any;
       Sin_Zero   : C.char_array (1 .. 8) := (others => C.char'Val (0));
@@ -79,6 +79,13 @@
    pragma Convention (C, Sockaddr_In);
    --  Internet socket address
 
+   Null_Sockaddr_In : constant Sockaddr_In := (
+@SA_LEN@      Sin_Len    => 18,
+      Sin_Family => 0,
+      Sin_Port   => 0,
+      Sin_Addr   => Inaddr_Any,
+      Sin_Zero   => (others => C.char'Val (0)));
+
    type Sockaddr_In_Access is access all Sockaddr_In;
    pragma Convention (C, Sockaddr_In_Access);
    --  Access to internet socket address
Index: src/Makefile.am
===================================================================
--- src/Makefile.am	(revision 1616)
+++ src/Makefile.am	(working copy)
@@ -42,7 +42,7 @@
 
 ADAFLAGS = @ADAFLAGS@ -I. -I$(srcdir)
 
-CLEANFILES = *.o *.ali
+CLEANFILES = *.o *.ali b~*
 DISTCLEANFILES = b_split.c split constants_nodef \
 		sockets-thin.ads sockets-thin.adb
 

--Boundary-00=_X7lmLhaoOTZG6mQ
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
AdaSockets mailing list
[email protected]
http://lists.rfc1149.net/mailman/listinfo/adasockets

--Boundary-00=_X7lmLhaoOTZG6mQ--