source: rtems/c/src/lib/libbsp/i386/ts_386ex/tools/network_ada/adasockets/sockets.ads @ d0fa0ef

Last change on this file since d0fa0ef was 1d4048b2, checked in by Joel Sherrill <joel.sherrill@…>, on 08/11/99 at 23:45:57

Patch from Tony R. Ambardar <tonya@…>:

I'm attaching a big patch for the ts_386ex BSP which adds and includes
the following:

1) Conversion to ELF format + minor code cleanups + documentation.

2) An Ada95 binding to FreeBSD sockets, based on Samuel Tardieu's

adasockets-0.1.3 package. This includes some sample applications.

3) Some Ada and C interfaces to add serial-port debugging to

programs. Comes with examples, too; the Ada one shows how
transparent adding the support can be. Note that Rosimildo sent me
the original C code.

The network stuff is not BSP specific, and could be added to your Ada
code collection. The debugging stuff is specific to the i386. Right
now, everything sits in my "tools" directory.

  • Property mode set to 100644
File size: 6.3 KB
Line 
1-----------------------------------------------------------------------------
2--                                                                         --
3--                         ADASOCKETS COMPONENTS                           --
4--                                                                         --
5--                             S O C K E T S                               --
6--                                                                         --
7--                                S p e c                                  --
8--                                                                         --
9--                        $ReleaseVersion: 0.1.3 $                         --
10--                                                                         --
11--  Copyright (C) 1998  École Nationale Supérieure des Télécommunications  --
12--                                                                         --
13--   AdaSockets is free software; you can  redistribute it and/or modify   --
14--   it  under terms of the GNU  General  Public License as published by   --
15--   the Free Software Foundation; either version 2, or (at your option)   --
16--   any later version.   AdaSockets is distributed  in the hope that it   --
17--   will be useful, but WITHOUT ANY  WARRANTY; without even the implied   --
18--   warranty of MERCHANTABILITY   or FITNESS FOR  A PARTICULAR PURPOSE.   --
19--   See the GNU General Public  License  for more details.  You  should   --
20--   have received a copy of the  GNU General Public License distributed   --
21--   with AdaSockets; see   file COPYING.  If  not,  write  to  the Free   --
22--   Software  Foundation, 59   Temple Place -   Suite  330,  Boston, MA   --
23--   02111-1307, USA.                                                      --
24--                                                                         --
25--   As a special exception, if  other  files instantiate generics  from   --
26--   this unit, or  you link this  unit with other  files to produce  an   --
27--   executable,  this  unit does  not  by  itself cause  the  resulting   --
28--   executable to be  covered by the  GNU General Public License.  This   --
29--   exception does  not  however invalidate any  other reasons  why the   --
30--   executable file might be covered by the GNU Public License.           --
31--                                                                         --
32--   The main repository for this software is located at:                  --
33--       http://www-inf.enst.fr/ANC/                                       --
34--                                                                         --
35-----------------------------------------------------------------------------
36
37with Ada.Streams;
38with Interfaces.C;
39
40package Sockets is
41
42   type Socket_FD is tagged private;
43   --  A socket
44
45   type Socket_Domain is (AF_INET);
46   --  AF_INET: Internet sockets (yes, should be PF_INET, but they hold the
47   --  same value)
48
49   type Socket_Type is (SOCK_STREAM, SOCK_DGRAM);
50   --  SOCK_STREAM: Stream mode   (TCP)
51   --  SOCK_DGRAM:  Datagram mode (UDP, Multicast)
52
53   procedure Socket
54     (Sock   : out Socket_FD;
55      Domain : in Socket_Domain := AF_INET;
56      Typ    : in Socket_Type   := SOCK_STREAM);
57   --  Create a socket of the given mode
58
59   Connection_Refused : exception;
60
61   procedure Connect
62     (Socket : in Socket_FD;
63      Host   : in String;
64      Port   : in Positive);
65   --  Connect a socket on a given host/port. Raise Connection_Refused if
66   --  the connection has not been accepted by the other end.
67
68   procedure Bind
69     (Socket : in Socket_FD;
70      Port   : in Positive);
71   --  Bind a socket on a given port
72
73   procedure Listen
74     (Socket     : in Socket_FD;
75      Queue_Size : in Positive := 5);
76   --  Create a socket's listen queue
77
78   type Socket_Level is (SOL_SOCKET, IPPROTO_IP);
79
80   type Socket_Option is (SO_REUSEADDR, IP_MULTICAST_TTL,
81                          IP_ADD_MEMBERSHIP, IP_DROP_MEMBERSHIP,
82                          IP_MULTICAST_LOOP);
83
84   procedure Setsockopt
85     (Socket  : in Socket_FD'Class;
86      Level   : in Socket_Level := SOL_SOCKET;
87      Optname : in Socket_Option;
88      Optval  : in Integer);
89   --  Set a socket option
90
91   generic
92      Level   : Socket_Level;
93      Optname : Socket_Option;
94      type Opt_Type is private;
95   procedure Customized_Setsockopt (Socket : in Socket_FD'Class;
96                                    Optval : in Opt_Type);
97   --  Low level control on setsockopt
98
99   procedure Accept_Socket (Socket     : in Socket_FD;
100                            New_Socket : out Socket_FD);
101   --  Accept a connection on a socket
102
103   Connection_Closed : exception;
104
105   procedure Send (Socket : in Socket_FD;
106                   Data   : in Ada.Streams.Stream_Element_Array);
107   --  Send data on a socket. Raise Connection_Closed if the socket
108   --  has been closed.
109
110   function Receive (Socket : Socket_FD;
111                     Max    : Ada.Streams.Stream_Element_Count := 4096)
112     return Ada.Streams.Stream_Element_Array;
113   --  Receive data from a socket. May raise Connection_Closed
114
115   procedure Receive (Socket : in Socket_FD'Class;
116                      Data   : out Ada.Streams.Stream_Element_Array);
117   --  Fill data from a socket. Raise Connection_Closed if the socket has
118   --  been closed before the end of the array.
119
120   type Shutdown_Type is (Receive, Send, Both);
121
122   procedure Shutdown (Socket : in Socket_FD;
123                       How    : in Shutdown_Type := Both);
124   --  Close a previously opened socket
125
126   ---------------------------------
127   -- String-oriented subprograms --
128   ---------------------------------
129
130   procedure Put (Socket : in Socket_FD'Class;
131                  Str    : in String);
132   --  Send a string on the socket
133
134   procedure New_Line (Socket : in Socket_FD'Class;
135                       Count  : in Natural := 1);
136   --  Send CR/LF sequences on the socket
137
138   procedure Put_Line (Socket : in Socket_FD'Class;
139                       Str    : in String);
140   --  Send a string + CR/LF on the socket
141
142   function Get (Socket : Socket_FD'Class) return String;
143   --  Get a string from the socket
144
145   function Get_Line (Socket : Socket_FD'Class) return String;
146   --  Get a full line from the socket. CR is ignored and LF is considered
147   --  as an end-of-line marker.
148
149private
150
151   type Socket_FD is tagged record
152      FD : Interfaces.C.int;
153   end record;
154
155end Sockets;
Note: See TracBrowser for help on using the repository browser.