-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgnat-sockets-server.ads
1721 lines (1705 loc) · 54.8 KB
/
gnat-sockets-server.ads
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- --
-- package GNAT.Sockets.Server Copyright (c) Dmitry A. Kazakov --
-- Interface Luebeck --
-- Winter, 2012 --
-- --
-- Last revision : 14:52 29 Feb 2020 --
-- --
-- This library 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. This library --
-- 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. You should have --
-- received a copy of the GNU General Public License along with --
-- this library; if not, write to the Free Software Foundation, --
-- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. --
-- --
-- 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. --
--____________________________________________________________________--
with Ada.Exceptions; use Ada.Exceptions;
with Ada.Streams; use Ada.Streams;
with Ada.Finalization;
with Ada.Text_IO;
with Object.Handle.Generic_Unbounded_Array;
with Strings_Edit.Integer_Edit;
package GNAT.Sockets.Server is
Connection_Error : exception;
subtype Buffer_Length is
Stream_Element_Offset range 1..Stream_Element_Offset'Last;
--
-- IO_Tracing_Mode -- Tracing incoming and outgoing data
--
type IO_Tracing_Mode is
( Trace_None, -- Don't trace anything
Trace_Encoded, -- Trace encoded/ciphered data
Trace_Any, -- Trace all data
Trace_Decoded -- Trace plain data
);
--
-- Session_State -- Of a connection
--
type Session_State is
( Session_Down, -- Not in use
Session_Disconnected, -- Not connected
Session_Connecting, -- Pending connection to a remote host
Session_Handshaking, -- Pending handshake
Session_Connected, -- Connected
Session_Active, -- Connected and operating
Session_Busy -- Pending modal operation
);
--
-- To_Addr -- Convert host name or dotted address to address
--
-- Host - The host name or address
--
-- Returns :
--
-- The corresponding address
--
-- Exceptions :
--
-- Socket_Error - Invalid address or host name
--
function To_Addr (Host : String) return Inet_Addr_Type;
--
-- Connection -- To derive custom object handling a client connection
--
-- Input_Size - Input buffer size
-- Output_Size - Output buffer size
--
-- The input buffer determines maximal number of octets received from
-- the client in one piece. Usually it is around the average packet
-- size, though one must not expect that packets will be delivered as a
-- whole, per single call to Received. The output buffer is the maximal
-- number of octets which can be sent in one piece without postponing
-- sending.
--
type Connection
( Input_Size : Buffer_Length;
Output_Size : Buffer_Length
) is abstract new Object.Entity with private;
type Connection_Ptr is access all Connection'Class;
--
-- Connections_Factory -- Factory of client connection objects
--
type Connections_Factory is
new Ada.Finalization.Limited_Controlled with private;
--
-- Encoder -- The transport layer, connection is encoded/ciphered
--
-- Size - The decoded content buffer size
--
type Encoder (Size : Buffer_Length) is abstract
new Ada.Finalization.Limited_Controlled with private;
type Encoder_Ptr is access all Encoder'Class;
--
-- Server -- To derive a custom multiple connections server from
--
-- Port - The port to listen
--
type Connections_Server
( Factory : access Connections_Factory'Class;
Port : Port_Type
) is new Ada.Finalization.Limited_Controlled with private;
type Connections_Server_Ptr is access all Connections_Server'Class;
--
-- Activated -- Session activation notification
--
-- Client - The client connection object
--
-- This procedure is called when the session becomes active after
-- handshake completion. From here a server or client can initiate
-- communication with the pier. The default implementation does nothing.
--
procedure Activated (Client : in out Connection);
--
-- Available_To_Process -- Stream elements available to process
--
-- Client - The client connection object
--
-- Returns :
--
-- Count of received but not yet processed stream elements
--
function Available_To_Process (Client : Connection)
return Stream_Element_Count;
--
-- Available_To_Send -- Stream elements available to send
--
-- Client - The client connection object
--
-- The result is the maximum number of stream elements which Send is
-- guaranteed to accept. Larger number may cause Send returning Pointer
-- less or equal to Data'Last.
--
-- Returns :
--
-- Stream elements count
--
function Available_To_Send (Client : Connection)
return Stream_Element_Count;
--
-- Connect -- Connect to a server
--
-- Listener - The server object
-- Client - The client connection object
-- Host - The host name or IP address
-- Port - The port number
-- Max_Connect_No - Maximal number of connection attempts
-- Overlapped - The overlapped read size (full-duplex by default)
--
-- This procedure is used to create a client connection to a server.
-- This is opposite to accepting connection. Connection is asynchronous.
-- When successful, Connected is called as usual. When the connection
-- is dropped Disconnect is called and an attempt made to reconnect.
-- Note that the connection object is passed by pointer an maintained by
-- Listener.
--
-- Exceptions :
--
-- Host_Error - Invalid host name
-- Socket_Error - Socket error
-- Use_Error - Client is already in use
--
procedure Connect
( Listener : in out Connections_Server;
Client : Connection_Ptr;
Host : String;
Port : Port_Type;
Max_Connect_No : Positive := Positive'Last;
Overlapped : Stream_Element_Count :=
Stream_Element_Count'Last
);
--
-- Connect_Error -- Failed to connect
--
-- Client - The client connection object
-- Error - The socket error
--
-- This procedure is called on a connection object if an attempt to
-- connect to a remote host initiated by Connect failed. Next connection
-- attempt will be made after return from the procedure. The default
-- implementation does nothing.
--
-- Exceptions :
--
-- Connection_Error - Stop attempts and collect the object
--
procedure Connect_Error
( Client : in out Connection;
Error : Error_Type
);
--
-- Connect_Parameters_Set -- Notification
--
-- Client - The client connection object
-- Host - Remote host name or address as given in Connect
-- Address - Remote host address
-- Max_Connect_No - Maximal number of connection attempts
--
-- This procedure is called when connection parameters are set for an
-- outgoing connection. The default implementation does nothing. If
-- overridden, the new implementation should probably call the parent's
-- implementation.
--
procedure Connect_Parameters_Set
( Client : in out Connection;
Host : String;
Address : Sock_Addr_Type;
Max_Connect_No : Positive
);
--
-- Connected -- The first operation called on a connection object
--
-- Client - The client connection object
--
-- The default implementation does nothing. Typically the server may
-- set some socket options here. The implementation must call the
-- parent's implementation of this procedure from the overriding.
--
-- Exceptions :
--
-- Connection_Error - Is propagated when decided to refuse connection
-- other - Other errors
--
procedure Connected (Client : in out Connection);
--
-- Connected -- Server notification about client connection
--
-- Listener - The server object
-- Client - The client object
--
-- The server may do some bookkeeping here. It is called after Client's
-- Connected is. The default implementation does nothing.
--
-- Exceptions :
--
-- Connection_Error - Is propagated when decided to refuse connection
-- other - Other errors
--
procedure Connected
( Listener : in out Connections_Server;
Client : in out Connection'Class
);
--
-- Create -- Client connection object
--
-- Factory - The factory object
-- Listener - The server object
-- From - The client address
--
-- This function is called to accept connection from a client. The
-- implementation may refuse connection in which case it returns null.
-- When connection is accepted the implementation allocates a new
-- connection object and returns a pointer to it. Note that it is the
-- server object responsibility to free the object. The implementation
-- may deploy client filtering based on the address From and/or number
-- of connections. The default implementation returns null.
--
-- Returns :
--
-- Pointer to the connection object or null
--
function Create
( Factory : access Connections_Factory;
Listener : access Connections_Server'Class;
From : Sock_Addr_Type
) return Connection_Ptr;
--
-- Create_Socket -- Listener socket creation
--
-- Listener - The server object
-- Socket - The socket to create
-- Address - The address to bind the socket to
--
-- This procedure is called to create the socket the server will listen
-- to. The default implementation creates the socket, sets socket reuse
-- option, binds the socket to Address, listens to the socket. If Socket
-- remains No_Socket the worker task of connection server will ends.
--
procedure Create_Socket
( Listener : in out Connections_Server;
Socket : in out Socket_Type;
Address : Sock_Addr_Type
);
--
-- Create_Transport -- Client connection object
--
-- Factory - The factory object
-- Listener - The server object
-- Client - The client for which the transport is created
--
-- This function is called after accepting connection from a client or
-- successfull connection to a server to setup transport if enoding/
-- ciphering is required. The returned object is owned by the server, it
-- is finalized and freed when no more used. The default implementation
-- returns null to indicate no encoding.
--
-- Returns :
--
-- Pointer to the encoder object or null
--
function Create_Transport
( Factory : access Connections_Factory;
Listener : access Connections_Server'Class;
Client : access Connection'Class
) return Encoder_Ptr;
--
-- Create_Transport -- Continue with a transport layer
--
-- Client - The connection object
--
-- The connections with Is_Opportunistic returning true do not start
-- secure exchange until this procedure is called.
--
-- Exceptions :
--
-- Status_Error - The connection is already secured
-- Use_Error - No secure secure connections support
--
procedure Create_Transport (Client : in out Connection);
--
-- Disconnected -- Client disconnection notification
--
-- Client - The client object
--
-- The default implementation does nothing. If overridden the new
-- implementation shall call the parent's one.
--
-- Exceptions :
--
-- Connection_Error - Do not reconnect
--
procedure Disconnected (Client : in out Connection);
--
-- Disconnected -- Server notification about client disconnection
--
-- Listener - The server object
-- Client - The client object being deleted
--
-- The server may do some bookkeeping here. It is called before Client's
-- Disconnected is.
--
-- Exceptions :
--
-- Connection_Error - Do not reconnect
--
procedure Disconnected
( Listener : in out Connections_Server;
Client : in out Connection'Class
);
--
-- Downed -- Client shutdown notification
--
-- Client - The client object
--
-- The default implementation does nothing.
--
procedure Downed (Client : in out Connection);
--
-- Downed -- Server notification about client shutdown
--
-- Listener - The server object
-- Client - The client object being deleted
--
-- The server may do some bookkeeping here. It is called before Client's
-- Downed is.
--
procedure Downed
( Listener : in out Connections_Server;
Client : in out Connection'Class
);
--
-- Elevated -- Notification of opportunistic transport creation
--
-- Client - The connection object
--
-- This procedure is called when an opportunistic transport layer is
-- created and ready to use. When a connection with Is_Opportunistic
-- returning True calls Create_Transport this creates a transport layer,
-- usually encrypted, and after successful handshake this procedure is
-- called.
--
procedure Elevated (Client : in out Connection);
--
-- Encode -- Encode and send
--
-- Transport - The transport object
-- Client - The client connection object
-- Data - To encode
-- Last - The last element encoded
--
-- This procedure is called when the transport encoder is set. The
-- implementation must encode a portion of Data and send it to the
-- client. Last is set to the last encoded element.
--
procedure Encode
( Transport : in out Encoder;
Client : in out Connection'Class;
Data : Stream_Element_Array;
Last : out Stream_Element_Offset
) is abstract;
--
-- Finalize -- Destruction
--
-- Listener - The server object
--
-- The derived type must call this procedure when it overrides this.
--
procedure Finalize (Listener : in out Connections_Server);
--
-- Finalize -- Destruction
--
-- Client - The connection object
--
-- The derived type must call this procedure when it overrides this.
--
procedure Finalize (Client : in out Connection);
--
-- From_String -- Conversion from string
--
-- Data - To convert
--
-- Returns :
--
-- The result
--
function From_String (Data : String) return Stream_Element_Array;
--
-- Get_Clients_Count -- Number of clients connected
--
-- Listener - The server object
--
-- Returns :
--
-- Number of connected clients
--
function Get_Clients_Count (Listener : Connections_Server)
return Natural;
--
-- Get_Client_Address -- Get address of the client
--
-- Client - The client connection object
--
-- Returns :
--
-- The client's address
--
function Get_Client_Address (Client : Connection)
return Sock_Addr_Type;
--
-- Get_Client_Name -- Get the name of the client
--
-- Factory - The factory object
-- Client - The client connection object
--
-- The default implementation uses IP address returned by the function
-- Get_Client_Address for the client name.
--
-- Returns :
--
-- The client's name used in tracing
--
function Get_Client_Name
( Factory : Connections_Factory;
Client : Connection'Class
) return String;
--
-- Get_Connections_Server -- Get client's connections server
--
-- Client - The client connection object
--
-- Returns :
--
-- A pointer to the connections server or null
--
function Get_Connections_Server (Client : Connection)
return Connections_Server_Ptr;
--
-- Get_IO_Timeout -- The I/O timeout used by connections server
--
-- Factory - The factory object
--
-- When the connections server waits for a socket to become readable or
-- writable this value specifies waiting timeout. Upon the timeout the
-- server re-enters the waiting. The default value is 20ms. It can be
-- changed by overriding this function.
--
-- Returns :
--
-- The timeout when waiting for sockets events
--
function Get_IO_Timeout (Factory : Connections_Factory)
return Duration;
--
-- Get_Occurrence -- Get saved client error
--
-- Client - The client connection object
-- Source - Saved exception occurence
--
procedure Get_Occurrence
( Client : Connection;
Source : out Exception_Occurrence
);
--
-- Get_Overlapped_Size -- Get read policy
--
-- Client - The client connection object
--
-- See Set_Overlapped_Size.
--
-- Returns :
--
-- Maximum number of elements queued to send before blocking receive
--
function Get_Overlapped_Size (Client : Connection)
return Stream_Element_Count;
--
-- Get_Polling_Timeout -- The polling timeout used by connections server
--
-- Factory - The factory object
--
-- The connections server stops polling a socket for being writable for
-- no longer than the value returned by this function. The default value
-- is 0.5s. The function can be overridden in order to change the value.
--
-- Returns :
--
-- The timeout before unblocking sending
--
function Get_Polling_Timeout (Factory : Connections_Factory)
return Duration;
--
-- Get_Server_Address -- Get the server socket address
--
-- Listener - The server object
--
-- This function is called before the server starts listening. The
-- result is the address to listen. The default implementation returns
-- an addressof the INET family with any address and the port taken
-- from the argument's port discriminant.
--
-- Returns :
--
-- The address to listen
--
function Get_Server_Address
( Listener : Connections_Server
) return Sock_Addr_Type;
--
-- Get_Session_State -- Session state
--
-- Client - The client connection object
--
-- Returns :
--
-- Current state
--
function Get_Session_State (Client : Connection)
return Session_State;
--
-- Get_Socket -- Get the socket
--
-- Client - The client connection object
--
-- Returns :
--
-- The socket used
--
function Get_Socket (Client : Connection) return Socket_Type;
--
-- Has_Data -- Check if there is input data ready to process
--
-- Client - The client connection object
--
-- Returns :
--
-- True if the are data to process
--
function Has_Data (Client : Connection) return Boolean;
--
-- Image -- Conversion to string
--
-- Code - Socket error type
--
-- Returns :
--
-- Textual representation of
--
function Image (Code : Error_Type) return String;
--
-- Image -- Printable representation of stream array
--
-- Data - To convert
-- Hexadecimal - If true HH HH HH form is used intead of cc%hhc%hh
--
-- The default output looks like:
--
-- source line%0D%0A
--
-- The hexadecimal output of the same data is
--
-- 73 6F 75 72 63 65 20 6C 69 6E 65 0D 0A
--
-- Returns :
--
-- Printable representation of
--
function Image
( Data : Stream_Element_Array;
Hexadecimal : Boolean := False
) return String;
--
-- Initialize -- Construction
--
-- Listener - The server object
--
-- The derived type must call this procedure from its implementation
-- when it replaces it.
--
procedure Initialize (Listener : in out Connections_Server);
--
-- Is_Connected -- Connection status
--
-- Client - The client connection object
--
-- Returns :
--
-- True if the client is connected
--
function Is_Connected (Client : Connection) return Boolean;
--
-- Is_Down -- Connection object status
--
-- Client - The client connection object
--
-- This function is used to check if the object is still functional,
-- that whether it is connected or else tries to connect. When True is
-- returned an outgoing connection object can be reused, e.g. connected
-- again.
--
-- Returns :
--
-- True if the client is down
--
function Is_Down (Client : Connection) return Boolean;
--
-- Is_Elevated -- Check if connection uses a transport layer
--
-- Client - The client connection object
--
-- Returns :
--
-- True if a transport layer is present
--
function Is_Elevated (Client : Connection) return Boolean;
--
-- Is_Incoming -- Connection type
--
-- Client - The client connection object
--
-- Returns :
--
-- True if client handles and incoming connection
--
function Is_Incoming (Client : Connection) return Boolean;
--
-- Is_Opportunistic -- Secure connection type
--
-- Client - The client connection object
--
-- This function returns True if the connection deploys opportunistic
-- security encoding. The default is False, that means the connection
-- engages security transport immediately once established. When True
-- the exchange starts not secured and turns into secure mode only when
-- both parties agree on that. An example of opportunistic secure
-- connection is SMTP's STARTTLS command.
--
-- Returns :
--
-- True if the connection deploys opportunistic security encoding
--
function Is_Opportunistic (Client : Connection) return Boolean;
--
-- Is_TLS_Capable -- Secure connection type
--
-- Factory - The factory object
--
-- The default implementation returns False
--
-- Returns :
--
-- True if the factory can create TLS transport
--
function Is_TLS_Capable
( Factory : Connections_Factory
) return Boolean;
--
-- Is_Trace_Received_On -- Tracing state
--
-- Factory - The factory object
-- Encoded - The type of content trace to check
--
-- Returns :
--
-- True if tracing received data is on
--
function Is_Trace_Received_On
( Factory : Connections_Factory;
Encoded : IO_Tracing_Mode
) return Boolean;
--
-- Is_Trace_Sent_On -- Tracing state
--
-- Factory - The factory object
-- Encoded - The type of content trace to check
--
-- Returns :
--
-- True if tracing sent data is on
--
function Is_Trace_Sent_On
( Factory : Connections_Factory;
Encoded : IO_Tracing_Mode
) return Boolean;
--
-- Is_Unblock_Send_Queued -- Tracing state
--
-- Listener - The connections server
--
-- Returns :
--
-- True if unblock send is queued
--
function Is_Unblock_Send_Queued
( Listener : Connections_Server
) return Boolean;
--
-- Keep_On_Sending -- Delay stopping sending
--
-- Client - The client connection object
--
-- This procedure is called to hint the connections server that it
-- should not stop polling the socket for being writable, because some
-- content to send is about to come.
--
procedure Keep_On_Sending (Client : in out Connection);
--
-- On_Worker_Start -- Worker task notification start
--
-- Listener - The server object
--
-- This procedure is called when the worker task starts. The default
-- implementation does nothing.
--
procedure On_Worker_Start (Listener : in out Connections_Server);
--
-- Process -- Encoded data processing
--
-- Transport - The encoder object
-- Listener - The server object
-- Client - The connection client
-- Data_Left - Unprocessed encoded input left
--
-- This procedure is called to handle a portion of incoming encoded
-- data.
--
procedure Process
( Transport : in out Encoder;
Listener : in out Connections_Server'Class;
Client : in out Connection'Class;
Data_Left : out Boolean
) is abstract;
--
-- Process_Packet -- Packet processing
--
-- Client - The connection client
--
-- This procedure is called when all fields of Client, e.g. with the
-- types derived from Data_Item have been received from the client.
-- The default implementation does nothing.
--
procedure Process_Packet (Client : in out Connection);
--
-- Queued_To_Send -- Stream elements queued to send
--
-- Client - The client connection object
--
-- Returns :
--
-- Stream elements count
--
function Queued_To_Send (Client : Connection)
return Stream_Element_Count;
--
-- Received -- Data received notification
--
-- Client - The client connection object
-- Data - The data
-- Pointer - First unprocessed element
--
-- This procedure is called when a portion of data is read from the
-- socket. The parameter Pointer is Data'Last + 1. It can be changed to
-- indicate the first unprocessed element. Data (Pointer..Data'Last)
-- stay in the buffer until a next call to Received. The default
-- implementation raises Connection_Error.
--
-- Exceptions :
--
-- Connection_Error - Propagated to close connection
--
procedure Received
( Client : in out Connection;
Data : Stream_Element_Array;
Pointer : in out Stream_Element_Offset
);
--
-- Received -- Data received notification
--
-- Factory - The factory object
-- Client - The client connection object
-- Data - The data received
-- From - The first received element in Data
-- To - The las received element in Data
--
-- This procedure is called when a portion of data is read from the
-- socket. The default implementation traces the input.
--
procedure Received
( Factory : in out Connections_Factory;
Client : in out Connection'Class;
Data : Stream_Element_Array;
From : Stream_Element_Offset;
To : Stream_Element_Offset
);
--
-- Receive_Error -- Data receive error
--
-- Client - The client connection object
-- Occurrence - The socket error
--
-- This procedure is called upon socket receive error before the
-- connection is dropped. The default implementation does nothing.
--
procedure Receive_Error
( Client : in out Connection;
Occurrence : Exception_Occurrence
);
--
-- Reconnect -- Drop current connection and try to reconnect
--
-- Client - The client connection object
--
-- Exception :
--
-- Mode_Error - A server or permanent connection
-- Status_Error - The client is down
-- Use_Error - Never connected before
--
procedure Reconnect (Client : in out Connection);
--
-- Released -- Notification
--
-- Client - The connection client
--
-- This procedure is called when Client is no more in use. The default
-- implementation does nothing.
--
procedure Released (Client : in out Connection);
--
-- Save_Occurrence -- Save client error occurence
--
-- Client - The client connection object
-- Source - The exception occurence to save
--
procedure Save_Occurrence
( Client : in out Connection;
Source : Exception_Occurrence
);
--
-- Send -- Data to the client
--
-- Client - The client connection object
-- Data - The data to send
-- Pointer - The first element to send
--
-- This procedure does not block. When no send is pending it sends as
-- much data the socket accepts without blocking. The rest is queued for
-- later which is also the case when some data are pending. The number
-- of elements available for queuing is returned by Available_To_Send.
-- The elements which cannot be queued are Data (Pointer..Data'Last).
-- When this happens they should be kept until Send is called and passed
-- to Send again from there.
--
-- Exceptions :
--
-- Socket_Error - Send error
-- Layout_Error - Pointer is not in Data'First..Data'Last + 1
--
procedure Send
( Client : in out Connection;
Data : Stream_Element_Array;
Pointer : in out Stream_Element_Offset
);
procedure Send
( Client : in out Connection;
Data : String;
Pointer : in out Integer
);
--
-- Send -- Data to the client
--
-- Client - The client connection object
-- Stream - To get data from to send
-- [ Count ] - Maximal number of elements to send
-- [ Reserve - Number of elements to reserve
-- Get_Prefix - Called to get prefix
-- Get_Suffix ] - Called to get suffix
-- End_Of_Stream - True if end of stream was reached
--
-- These procedures do not block. End_Of_Stream is set to False when the
-- caller should attempt later. The procedures read as much data from
-- Stream as possible and send it to the client. The length of the chunk
-- is determined by free contiguous space in the output buffer and the
-- number of elements returned by Stream. The parameter Reserve
-- specifies the maximum elements to reserve in the output buffer for
-- the prefix and suffix returned by Get_Prefix and Get_Suffix. The
-- prefix is sent before and the suffix after the chunk of data read
-- from Stream. When the parameter Count is specified, it limits the
-- number of elements sent. The procedure ends when Count reaches 0.
-- When Stream ends prematurely End_Of_Stream is True and Count is
-- non-zero. Count value does not limit prefix and suffix when these are
-- used.
--
-- Exceptions :
--
-- Data_Error - Output buffer is too small for prefix and suffix
-- Socket_Error - Send error
--
procedure Send
( Client : in out Connection;
Stream : in out Root_Stream_Type'Class;
End_Of_Stream : out Boolean
);
procedure Send
( Client : in out Connection;
Stream : in out Root_Stream_Type'Class;
Count : in out Stream_Element_Count;
End_Of_Stream : out Boolean
);
type Create_Stream_Element_Array is access function
( Client : access Connection'Class;
Data : Stream_Element_Array;
End_Of_Stream : Boolean
) return Stream_Element_Array;
procedure Send
( Client : in out Connection;
Stream : in out Root_Stream_Type'Class;
Count : in out Stream_Element_Count;
Reserve : Stream_Element_Count;
Get_Prefix : Create_Stream_Element_Array;
Get_Suffix : Create_Stream_Element_Array;
End_Of_Stream : out Boolean
);
procedure Send
( Client : in out Connection;
Stream : in out Root_Stream_Type'Class;
Reserve : Stream_Element_Count;
Get_Prefix : Create_Stream_Element_Array;
Get_Suffix : Create_Stream_Element_Array;
End_Of_Stream : out Boolean
);
type Create_String is access function
( Client : access Connection'Class;
Data : Stream_Element_Array;
End_Of_Stream : Boolean
) return String;
procedure Send
( Client : in out Connection;
Stream : in out Root_Stream_Type'Class;
Reserve : Natural;
Get_Prefix : Create_String;
Get_Suffix : Create_String;
End_Of_Stream : out Boolean
);
procedure Send
( Client : in out Connection;
Stream : in out Root_Stream_Type'Class;
Count : in out Stream_Element_Count;