Lines 57-81
Link Here
|
57 |
|
57 |
|
58 |
procedure Socket |
58 |
procedure Socket |
59 |
(Sock : out Socket_FD; |
59 |
(Sock : out Socket_FD; |
60 |
Domain : in Socket_Domain := PF_INET; |
60 |
Domain : Socket_Domain := PF_INET; |
61 |
Typ : in Socket_Type := SOCK_STREAM); |
61 |
Typ : Socket_Type := SOCK_STREAM); |
62 |
-- Create a socket of the given mode |
62 |
-- Create a socket of the given mode |
63 |
|
63 |
|
64 |
Connection_Refused : exception; |
64 |
Connection_Refused : exception; |
65 |
Socket_Error : exception; |
65 |
Socket_Error : exception; |
66 |
|
66 |
|
67 |
procedure Connect |
67 |
procedure Connect |
68 |
(Socket : in Socket_FD; |
68 |
(Socket : Socket_FD; |
69 |
Host : in String; |
69 |
Host : String; |
70 |
Port : in Positive); |
70 |
Port : Positive); |
71 |
-- Connect a socket on a given host/port. Raise Connection_Refused if |
71 |
-- Connect a socket on a given host/port. Raise Connection_Refused if |
72 |
-- the connection has not been accepted by the other end, or |
72 |
-- the connection has not been accepted by the other end, or |
73 |
-- Socket_Error (with a more precise exception message) for another error. |
73 |
-- Socket_Error (with a more precise exception message) for another error. |
74 |
|
74 |
|
75 |
procedure Bind |
75 |
procedure Bind |
76 |
(Socket : in Socket_FD; |
76 |
(Socket : Socket_FD; |
77 |
Port : in Natural; |
77 |
Port : Natural; |
78 |
Host : in String := ""); |
78 |
Host : String := ""); |
79 |
-- Bind a socket on a given port. Using 0 for the port will tell the |
79 |
-- Bind a socket on a given port. Using 0 for the port will tell the |
80 |
-- OS to allocate a non-privileged free port. The port can be later |
80 |
-- OS to allocate a non-privileged free port. The port can be later |
81 |
-- retrieved using Get_Sock_Port on the bound socket. |
81 |
-- retrieved using Get_Sock_Port on the bound socket. |
Lines 84-91
Link Here
|
84 |
-- Socket_Error can be raised if the system refuses to bind the port. |
84 |
-- Socket_Error can be raised if the system refuses to bind the port. |
85 |
|
85 |
|
86 |
procedure Listen |
86 |
procedure Listen |
87 |
(Socket : in Socket_FD; |
87 |
(Socket : Socket_FD; |
88 |
Queue_Size : in Positive := 5); |
88 |
Queue_Size : Positive := 5); |
89 |
-- Create a socket's listen queue |
89 |
-- Create a socket's listen queue |
90 |
|
90 |
|
91 |
type Socket_Level is (SOL_SOCKET, IPPROTO_IP); |
91 |
type Socket_Level is (SOL_SOCKET, IPPROTO_IP); |
Lines 95-129
Link Here
|
95 |
IP_MULTICAST_LOOP, SO_SNDBUF, SO_RCVBUF); |
95 |
IP_MULTICAST_LOOP, SO_SNDBUF, SO_RCVBUF); |
96 |
|
96 |
|
97 |
procedure Getsockopt |
97 |
procedure Getsockopt |
98 |
(Socket : in Socket_FD'Class; |
98 |
(Socket : Socket_FD'Class; |
99 |
Level : in Socket_Level := SOL_SOCKET; |
99 |
Level : Socket_Level := SOL_SOCKET; |
100 |
Optname : in Socket_Option; |
100 |
Optname : Socket_Option; |
101 |
Optval : out Integer); |
101 |
Optval : out Integer); |
102 |
-- Get a socket option |
102 |
-- Get a socket option |
103 |
|
103 |
|
104 |
procedure Setsockopt |
104 |
procedure Setsockopt |
105 |
(Socket : in Socket_FD'Class; |
105 |
(Socket : Socket_FD'Class; |
106 |
Level : in Socket_Level := SOL_SOCKET; |
106 |
Level : Socket_Level := SOL_SOCKET; |
107 |
Optname : in Socket_Option; |
107 |
Optname : Socket_Option; |
108 |
Optval : in Integer); |
108 |
Optval : Integer); |
109 |
-- Set a socket option |
109 |
-- Set a socket option |
110 |
|
110 |
|
111 |
generic |
111 |
generic |
112 |
Level : Socket_Level; |
112 |
Level : Socket_Level; |
113 |
Optname : Socket_Option; |
113 |
Optname : Socket_Option; |
114 |
type Opt_Type is private; |
114 |
type Opt_Type is private; |
115 |
procedure Customized_Setsockopt (Socket : in Socket_FD'Class; |
115 |
procedure Customized_Setsockopt (Socket : Socket_FD'Class; |
116 |
Optval : in Opt_Type); |
116 |
Optval : Opt_Type); |
117 |
-- Low level control on setsockopt |
117 |
-- Low level control on setsockopt |
118 |
|
118 |
|
119 |
procedure Accept_Socket (Socket : in Socket_FD; |
119 |
procedure Accept_Socket (Socket : Socket_FD; |
120 |
New_Socket : out Socket_FD); |
120 |
New_Socket : out Socket_FD); |
121 |
-- Accept a connection on a socket |
121 |
-- Accept a connection on a socket |
122 |
|
122 |
|
123 |
Connection_Closed : exception; |
123 |
Connection_Closed : exception; |
124 |
|
124 |
|
125 |
procedure Send (Socket : in Socket_FD; |
125 |
procedure Send (Socket : Socket_FD; |
126 |
Data : in Ada.Streams.Stream_Element_Array); |
126 |
Data : Ada.Streams.Stream_Element_Array); |
127 |
-- Send data on a socket. Raise Connection_Closed if the socket |
127 |
-- Send data on a socket. Raise Connection_Closed if the socket |
128 |
-- has been closed. |
128 |
-- has been closed. |
129 |
|
129 |
|
Lines 132-144
Link Here
|
132 |
return Ada.Streams.Stream_Element_Array; |
132 |
return Ada.Streams.Stream_Element_Array; |
133 |
-- Receive data from a socket. May raise Connection_Closed |
133 |
-- Receive data from a socket. May raise Connection_Closed |
134 |
|
134 |
|
135 |
procedure Receive (Socket : in Socket_FD'Class; |
135 |
procedure Receive (Socket : Socket_FD'Class; |
136 |
Data : out Ada.Streams.Stream_Element_Array); |
136 |
Data : out Ada.Streams.Stream_Element_Array); |
137 |
-- Get data from a socket. Raise Connection_Closed if the socket has |
137 |
-- Get data from a socket. Raise Connection_Closed if the socket has |
138 |
-- been closed before the end of the array. |
138 |
-- been closed before the end of the array. |
139 |
|
139 |
|
140 |
procedure Receive_Some |
140 |
procedure Receive_Some |
141 |
(Socket : in Socket_FD'Class; |
141 |
(Socket : Socket_FD'Class; |
142 |
Data : out Ada.Streams.Stream_Element_Array; |
142 |
Data : out Ada.Streams.Stream_Element_Array; |
143 |
Last : out Ada.Streams.Stream_Element_Offset); |
143 |
Last : out Ada.Streams.Stream_Element_Offset); |
144 |
-- Get some data from a socket. The index of the last element will |
144 |
-- Get some data from a socket. The index of the last element will |
Lines 147-163
Link Here
|
147 |
type Shutdown_Type is (Receive, Send, Both); |
147 |
type Shutdown_Type is (Receive, Send, Both); |
148 |
|
148 |
|
149 |
procedure Shutdown (Socket : in out Socket_FD; |
149 |
procedure Shutdown (Socket : in out Socket_FD; |
150 |
How : in Shutdown_Type := Both); |
150 |
How : Shutdown_Type := Both); |
151 |
-- Close a previously opened socket |
151 |
-- Close a previously opened socket |
152 |
|
152 |
|
153 |
procedure Socketpair |
153 |
procedure Socketpair |
154 |
(Read_End : out Socket_FD; |
154 |
(Read_End : out Socket_FD; |
155 |
Write_End : out Socket_FD; |
155 |
Write_End : out Socket_FD; |
156 |
Domain : in Socket_Domain := PF_INET; |
156 |
Domain : Socket_Domain := PF_INET; |
157 |
Typ : in Socket_Type := SOCK_STREAM); |
157 |
Typ : Socket_Type := SOCK_STREAM); |
158 |
-- Create a socketpair. |
158 |
-- Create a socketpair. |
159 |
|
159 |
|
160 |
function Get_FD (Socket : in Socket_FD) |
160 |
function Get_FD (Socket : Socket_FD) |
161 |
return Interfaces.C.int; |
161 |
return Interfaces.C.int; |
162 |
-- Get a socket's FD field |
162 |
-- Get a socket's FD field |
163 |
|
163 |
|
Lines 165-180
Link Here
|
165 |
-- String-oriented subprograms -- |
165 |
-- String-oriented subprograms -- |
166 |
--------------------------------- |
166 |
--------------------------------- |
167 |
|
167 |
|
168 |
procedure Put (Socket : in Socket_FD'Class; |
168 |
procedure Put (Socket : Socket_FD'Class; |
169 |
Str : in String); |
169 |
Str : String); |
170 |
-- Send a string on the socket |
170 |
-- Send a string on the socket |
171 |
|
171 |
|
172 |
procedure New_Line (Socket : in Socket_FD'Class; |
172 |
procedure New_Line (Socket : Socket_FD'Class; |
173 |
Count : in Natural := 1); |
173 |
Count : Natural := 1); |
174 |
-- Send CR/LF sequences on the socket |
174 |
-- Send CR/LF sequences on the socket |
175 |
|
175 |
|
176 |
procedure Put_Line (Socket : in Socket_FD'Class; |
176 |
procedure Put_Line (Socket : Socket_FD'Class; |
177 |
Str : in String); |
177 |
Str : String); |
178 |
-- Send a string + CR/LF on the socket |
178 |
-- Send a string + CR/LF on the socket |
179 |
|
179 |
|
180 |
function Get (Socket : Socket_FD'Class) return String; |
180 |
function Get (Socket : Socket_FD'Class) return String; |
Lines 195-201
Link Here
|
195 |
-- Function form for the former procedure |
195 |
-- Function form for the former procedure |
196 |
|
196 |
|
197 |
procedure Set_Buffer (Socket : in out Socket_FD'Class; |
197 |
procedure Set_Buffer (Socket : in out Socket_FD'Class; |
198 |
Length : in Positive := 1500); |
198 |
Length : Positive := 1500); |
199 |
-- Put socket in buffered mode. If the socket is already buffered, |
199 |
-- Put socket in buffered mode. If the socket is already buffered, |
200 |
-- the content of the previous buffer will be lost. The buffered mode |
200 |
-- the content of the previous buffer will be lost. The buffered mode |
201 |
-- only affects read operation, through Get, Get_Char and Get_Line. Other |
201 |
-- only affects read operation, through Get, Get_Char and Get_Line. Other |