[go: up one dir, main page]

File: anet-sockets-unix.ads

package info (click to toggle)
anet 0.3.3-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 800 kB
  • sloc: ada: 5,366; makefile: 120; sh: 19
file content (107 lines) | stat: -rw-r--r-- 3,926 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
--
--  Copyright (C) 2012      secunet Security Networks AG
--  Copyright (C) 2012-2016 Reto Buerki <reet@codelabs.ch>
--  Copyright (C) 2012-2016 Adrian-Ken Rueegsegger <ken@codelabs.ch>
--
--  This program is free software; you can redistribute it and/or modify it
--  under the terms of the GNU General Public License as published by the
--  Free Software Foundation; either version 2 of the License, or (at your
--  option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
--
--  This program is distributed in the hope that it will be useful, but
--  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
--  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
--  for more details.
--
--  As a special exception, if other files instantiate generics from this
--  unit,  or  you  link  this  unit  with  other  files  to  produce  an
--  executable   this  unit  does  not  by  itself  cause  the  resulting
--  executable to  be  covered by the  GNU General  Public License.  This
--  exception does  not  however  invalidate  any  other reasons why  the
--  executable file might be covered by the GNU Public License.
--

private with Ada.Strings.Unbounded;

with Anet.Sockets.Thin.Unix;

package Anet.Sockets.Unix is

   subtype Path_Range is Positive range 1 .. Thin.Unix.UNIX_PATH_MAX - 1;
   --  Range of unix paths.

   type Path_Type is array (Path_Range range <>) of Character;
   --  Unix path type.

   subtype Full_Path_Type is Path_Type (Path_Range);
   --  Unix path with max. possible size.

   function Is_Valid (Path : String) return Boolean;
   --  Returns true if the given path is a valid unix path.

   function To_String (Path : Full_Path_Type) return String;
   --  Returned trimmed string representation of given full path.

   type Unix_Socket_Type is abstract new Socket_Type with private;
   --  UNIX domain socket.

   overriding
   procedure Close (Socket : in out Unix_Socket_Type);
   --  Close given UNIX domain socket.

   procedure Bind
     (Socket : in out Unix_Socket_Type;
      Path   :        Path_Type);
   --  Bind given UNIX domain socket to path.

   procedure Connect
     (Socket : in out Unix_Socket_Type;
      Path   :        Path_Type);
   --  Connect given UNIX domain socket to path.

   type UDP_Socket_Type is new Unix_Socket_Type
     and Dgram_Socket_Type with private;
   --  UNIX domain socket in datagram mode.

   procedure Init (Socket : in out UDP_Socket_Type);
   --  Initialize given UNIX/UDP socket.

   procedure Receive
     (Socket :     UDP_Socket_Type;
      Src    : out Full_Path_Type;
      Item   : out Ada.Streams.Stream_Element_Array;
      Last   : out Ada.Streams.Stream_Element_Offset);
   --  Receive data from given Unix/UDP socket. This procedure blocks until
   --  data has been received. Last is the index value such that Item (Last) is
   --  the last character assigned. An exception is raised if a socket error
   --  occurs. The source argument is set to the socket path from which the
   --  data was received.

   type TCP_Socket_Type is new Unix_Socket_Type
     and Stream_Socket_Type with private;
   --  UNIX domain socket in stream mode.

   procedure Init (Socket : in out TCP_Socket_Type);
   --  Initialize given UNIX/TCP socket.

   overriding
   procedure Accept_Connection
     (Socket     :     TCP_Socket_Type;
      New_Socket : out TCP_Socket_Type);
   --  Accept first connection request from listening socket and return new
   --  connected socket.

private

   type Unix_Socket_Type is abstract new Socket_Type with record
      Path            : Ada.Strings.Unbounded.Unbounded_String;
      Delete_On_Close : Boolean := True;
   end record;

   type UDP_Socket_Type is new Unix_Socket_Type
     and Dgram_Socket_Type with null record;

   type TCP_Socket_Type is new Unix_Socket_Type
     and Stream_Socket_Type with null record;

end Anet.Sockets.Unix;