File: sockets.texi

package info (click to toggle)
adasockets 1.8.8-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 2,464 kB
  • ctags: 172
  • sloc: sh: 9,967; ada: 1,689; ansic: 357; makefile: 256
file content (1008 lines) | stat: -rw-r--r-- 29,460 bytes parent folder | download | duplicates (2)
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
1001
1002
1003
1004
1005
1006
1007
1008

The @code{Sockets} package contains all the definitions and
subprograms needed to build a simple unicast client or server.

@deftypefn Sockets.Socket_FD type Socket_FD is tagged private;
The @code{Socket_FD} tagged type is the root type of all
sockets. It gets initialized by calling @ref{Socket (procedure)}.
An uninitialized @code{Socket_FD} can be succesfully compared to
@code{Null_Socket_FD}.

@end deftypefn

@menu
* Accept_Socket (procedure)::
                        Accept an incoming connection
* Bind (procedure)::    Associate a local port to a socket
* Connect (procedure):: Connect a socket on a given host/port
* Get (function)::      Get a string from a remote host
* Get_Char (function):: Get a character from a remote host
* Get_Line (function):: Get a whole line from a remote host
* Get_Line (procedure)::
                        Get a whole line from a remote host
* Getsockopt (procedure)::
                        Retrieve a socket option
* Listen (procedure)::  Establish a listen queue
* New_Line (procedure)::
                        Send a CR/LF to a remote host
* Put (procedure)::     Send a string to a remote host
* Put_Line (procedure)::
                        Send a CR/LF terminated string to a remote host
* Receive (function)::  Receive raw data over a socket
* Receive (procedure):: Receive raw data over a socket
* Receive_Some (procedure)::
                        Receive raw data over a socket
* Send (procedure)::    Send raw data over a socket
* Set_Buffer (procedure)::
                        Install a line-oriented buffer of the socket object
* Setsockopt (procedure)::
                        Set a socket option
* Shutdown (procedure)::
                        Shutdown a socket
* Socket (procedure)::  Create a socket of the given mode
* Unset_Buffer (procedure)::
                        Deinstall the line-oriented buffer of the socket object
@end menu

@node Accept_Socket (procedure)
@unnumberedsubsec Accept_Socket (procedure)
@cindex Accepting a new connection
@cindex Handling a new connection

@table @sc
@item Purpose
Accept an incoming connection
@item Prototype
@deftypefn Sockets.Accept_Socket procedure Accept_Socket (@w{@var{Socket} : Socket_FD}; @w{@var{New_Socket} : out Socket_FD});
@end deftypefn
@fnindex Sockets.Accept_Socket

@item Parameters
@multitable {XXXXXXXX} {in out X} {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
@item @var{Socket} @tab in @tab Initialized
@item @var{New_Socket} @tab out @tab Incoming socket object
@end multitable


@item Description
This procedure creates a new socket corresponding to an incoming
connection on TCP socket @var{Socket}. All the communications
with the peer will take place on @var{New_Socket}, while the
program can accept another connection on @var{Socket}.

@var{New_Socket} must not be initialized before calling this
procedure, or must have been cleaned up by calling
@code{Shutdown}, in order to avoid a file descriptors leak.

@code{Accept_Socket} will block until an incoming connection is
ready to be accepted.



@item Example
@example
declare
   Sock     : Socket_FD;
   Incoming : Socket_FD;
begin
   -- Create a TCP socket listening on local port 4161
   Socket (Sock, PF_INET, SOCK_STREAM);
   Bind (Sock, 4161);
   Listen (Sock, 3);
   -- One-connection-at-a-time server (3 may be pending)
   loop
      -- Wait for a new connection and accept it
      Accept_Socket (Sock, Incoming);
      -- Do some dialog with the remote host
      Do_Some_Dialog (Incoming);
      -- Close incoming socket and wait for next connection
      Shutdown (Incoming);
   end loop;
end;
@end example


@item See also
@ref{Bind (procedure)},@*@ref{Listen (procedure)},@*@ref{Shutdown (procedure)},@*@ref{Socket (procedure)}.

@end table

@node Bind (procedure)
@unnumberedsubsec Bind (procedure)
@cindex Binding a socket
@cindex Assigning a local port
@cindex Creating a server

@table @sc
@item Purpose
Associate a local port to a socket
@item Prototype
@deftypefn Sockets.Bind procedure Bind (@w{@var{Socket} : Socket_FD}; @w{@var{Port} : Natural}; @w{@var{Host} : String := @w{}""});
@end deftypefn
@fnindex Sockets.Bind

@item Parameters
@multitable {XXXXXXXX} {in out X} {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
@item @var{Socket} @tab in @tab Initialized socket object
@item @var{Port} @tab in @tab Local port to bind to
@item @var{Host} @tab in @tab Local interface to bind to
@end multitable


@item Description
This procedure requests a local port from the operating
system. If 0 is given in @var{Port}, the system will assign a
free port whose number can later be retrieved using
@ref{Get_Sock_Port (function)}. Also, most operating systems require
special privileges if you want to bind to ports below 1024.

If @var{Host} is not the empty string, it must contain the
IP address of a local interface to bind to, or a name which
resolves into such an address. If an empty string is given (the
default), the socket will be bound to all the available
interfaces.


@item Exceptions
@multitable {XXXXXXXXXXXXXXXX} {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
@item @code{Socket_Error} @tab Requested port or interface not available@exindex Socket_Error
@end multitable





@item See also
@ref{Listen (procedure)},@*@ref{Socket (procedure)}.

@end table

@node Connect (procedure)
@unnumberedsubsec Connect (procedure)
@cindex Connecting a socket

@table @sc
@item Purpose
Connect a socket on a given host/port
@item Prototype
@deftypefn Sockets.Connect procedure Connect (@w{@var{Socket} : Socket_FD}; @w{@var{Host} : String}; @w{@var{Port} : Positive});
@end deftypefn
@fnindex Sockets.Connect

@item Parameters
@multitable {XXXXXXXX} {in out X} {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
@item @var{Socket} @tab in @tab Initialized socket object
@item @var{Host} @tab in @tab Host to connect to
@item @var{Port} @tab in @tab Port to connect to
@end multitable


@item Description
This procedure connects an initialized socket to a given host on
a given port. In the case of a TCP socket, a real connection is
attempted. In the case of a UDP socket, no connection takes place
but the endpoint coordinates are recorded.


@item Exceptions
@multitable {XXXXXXXXXXXXXXXX} {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
@item @code{Connection_Refused} @tab The connection has been refused by the server@exindex Connection_Refused
@item @code{Socket_Error} @tab Another error occurred during the connection@exindex Socket_Error
@end multitable





@item Example
@example
declare
   Sock : Socket_FD;
begin
   -- Create a TCP socket
   Socket (Sock, PF_INET, SOCK_STREAM);
   -- Connect it to rfc1149.net's mail server
   Connect (Sock, "mail.rfc1149.net", 25);
   -- Do a mail transaction then close the socket
   [...]
end;
@end example


@item See also
@ref{Socket (procedure)}.

@end table

@node Get (function)
@unnumberedsubsec Get (function)
@cindex Receiving data

@table @sc
@item Purpose
Get a string from a remote host
@item Prototype
@deftypefn Sockets.Get function Get (@w{@var{Socket} : Socket_FD'Class})@*@w{return String;}
@end deftypefn
@fnindex Sockets.Get

@item Parameters
@multitable {XXXXXXXX} {in out X} {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
@item @var{Socket} @tab in @tab Initialized and connected socket object
@end multitable

@item Return value
Some characters that have been received

@item Description
This function receives some characters from a remote host.
As soon that at least one character is available, the current
reception buffer is returned.

There is usually little gain in using this function whose behaviour is
comparable to the one of @ref{Receive (function)}. Other
functions such as @ref{Get_Char (function)}, or
@ref{Get_Line (function)}, allow more structured programming.

However, this function may be used to avoid loosing characters
when calling @ref{Unset_Buffer (procedure)}, if, for some reason,
the remote host may have sent some.


@item Exceptions
@multitable {XXXXXXXXXXXXXXXX} {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
@item @code{Connection_Closed} @tab Peer has closed the connection before sending any data@exindex Connection_Closed
@end multitable





@end table

@node Get_Char (function)
@unnumberedsubsec Get_Char (function)
@cindex Receiving data

@table @sc
@item Purpose
Get a character from a remote host
@item Prototype
@deftypefn Sockets.Get_Char function Get_Char (@w{@var{Socket} : Socket_FD'Class})@*@w{return Character;}
@end deftypefn
@fnindex Sockets.Get_Char

@item Parameters
@multitable {XXXXXXXX} {in out X} {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
@item @var{Socket} @tab in @tab Initialized and connected socket object
@end multitable

@item Return value
One character sent by the remote host

@item Description
This function receives exactly one character from the remote host.


@item Exceptions
@multitable {XXXXXXXXXXXXXXXX} {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
@item @code{Connection_Closed} @tab Peer has closed the connection before sending the character@exindex Connection_Closed
@end multitable





@item See also
@ref{Get (function)},@*@ref{Get_Line (function)},@*@ref{Get_Line (procedure)},@*@ref{Receive (procedure)},@*@ref{Set_Buffer (procedure)}.

@end table

@node Get_Line (function)
@unnumberedsubsec Get_Line (function)
@cindex Receiving data

@table @sc
@item Purpose
Get a whole line from a remote host
@item Prototype
@deftypefn Sockets.Get_Line function Get_Line (@w{@var{Socket} : Socket_FD'Class}; @w{@var{Max_Length} : Positive := 2048})@*@w{return String;}
@end deftypefn
@fnindex Sockets.Get_Line

@item Parameters
@multitable {XXXXXXXX} {in out X} {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
@item @var{Socket} @tab in @tab Initialized and connected socket object
@item @var{Max_Length} @tab in @tab Maximum returned line length
@end multitable

@item Return value
A line without the CR and LF separators

@item Description
@ctindex CR
@ctindex LF
This function receives one line from the remote host. A line
consists into zero or more characters followed by an optional CR
and by a LF. Those terminators are stripped before the line is
returned.

This function blocks until one full line has been received. The line
length is limited with the value of the Max_Length argument, to avoid
exhaustion of the secondary stack.


@item Exceptions
@multitable {XXXXXXXXXXXXXXXX} {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
@item @code{Connection_Closed} @tab Peer has closed the connection before sending a whole line@exindex Connection_Closed
@end multitable





@item See also
@ref{Get (function)},@*@ref{Get_Char (function)},@*@ref{Get_Line (procedure)},@*@ref{Receive (procedure)},@*@ref{Set_Buffer (procedure)}.

@end table

@node Get_Line (procedure)
@unnumberedsubsec Get_Line (procedure)
@cindex Receiving data

@table @sc
@item Purpose
Get a whole line from a remote host
@item Prototype
@deftypefn Sockets.Get_Line procedure Get_Line (@w{@var{Socket} : Socket_FD'Class}; @w{@var{Str} : in out String}; @w{@var{Last} : out Natural});
@end deftypefn
@fnindex Sockets.Get_Line

@item Parameters
@multitable {XXXXXXXX} {in out X} {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
@item @var{Socket} @tab in @tab Initialized and connected socket object
@item @var{Str} @tab in out @tab String to fill
@item @var{Last} @tab out @tab Last index used in the string
@end multitable


@item Description
@ctindex CR
@ctindex LF
This procedure receives one line from the remote host. A line
consists into zero or more characters followed by an optional CR
and by a LF. Those terminators are stripped before the line is
returned.

This procedure blocks until one full line has been received.


@item Exceptions
@multitable {XXXXXXXXXXXXXXXX} {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
@item @code{Connection_Closed} @tab Peer has closed the connection before sending a whole line@exindex Connection_Closed
@end multitable





@item See also
@ref{Get (function)},@*@ref{Get_Char (function)},@*@ref{Get_Line (function)},@*@ref{Receive (procedure)},@*@ref{Set_Buffer (procedure)}.

@end table

@node Getsockopt (procedure)
@unnumberedsubsec Getsockopt (procedure)
@cindex Manipulating socket options
@cindex Retrieving socket options

@table @sc
@item Purpose
Retrieve a socket option
@item Prototype
@deftypefn Sockets.Getsockopt procedure Getsockopt (@w{@var{Socket} : Socket_FD}; @w{@var{Level} : Socket_Level := SOL_SOCKET}; @w{@var{Optname} : Socket_Option}; @w{@var{Optval} : out Integer});
@end deftypefn
@fnindex Sockets.Getsockopt

@item Parameters
@multitable {XXXXXXXX} {in out X} {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
@item @var{Socket} @tab in @tab Initialized and bound socket object
@item @var{Level} @tab in @tab Protocol level
@item @var{Optname} @tab in @tab Option name
@item @var{Optval} @tab out @tab Option value
@end multitable


@item Description
@ctindex Sockets.SOL_SOCKET
@ctindex Sockets.IPPROTO_IP
@ctindex Sockets.SO_REUSEADDR
@ctindex Sockets.SO_REUSEPORT
@ctindex Sockets.IP_MULTICAST_TTL
@ctindex Sockets.IP_ADD_MEMBERSHIP
@ctindex Sockets.IP_DROP_MEMBERSHIP
@ctindex Sockets.IP_MULTICAST_LOOP
@ctindex Sockets.SO_SNDBUF
@ctindex Sockets.SO_RCVBUF
@ctindex SOL_SOCKET
@ctindex IPPROTO_IP
@ctindex SO_REUSEADDR
@ctindex SO_REUSEPORT
@ctindex IP_MULTICAST_TTL
@ctindex IP_ADD_MEMBERSHIP
@ctindex IP_DROP_MEMBERSHIP
@ctindex IP_MULTICAST_LOOP
@ctindex SO_SNDBUF
@ctindex SO_RCVBUF
This procedure retrieves options applicable to a socket. Please
see your operating system manual for usable levels and options.

Two levels are defined: @code{SOL_SOCKET} (the default) and
@code{IPPROTO_IP}. The options are @code{SO_REUSEADDR},
@code{SO_REUSEPORT}, @code{IP_MULTICAST_TTL},
@code{IP_ADD_MEMBERSHIP}, @code{IP_DROP_MEMBERSHIP},
@code{IP_MULTICAST_LOOP}, @code{SO_SNDBUF} and
@code{IP_RCVBUF}.

Note that unlike their C language counterpart, @code{Getsockopt}
and @code{Setsockopt} do not require an extra parameter
representing the length in bytes of the option value. AdaSockets
nows the right size for every option.




@item See also
@ref{Setsockopt (procedure)}.

@end table

@node Listen (procedure)
@unnumberedsubsec Listen (procedure)
@cindex Establishing a listen queue
@cindex Listen queue

@table @sc
@item Purpose
Establish a listen queue
@item Prototype
@deftypefn Sockets.Listen procedure Listen (@w{@var{Socket} : Socket_FD}; @w{@var{Queue_Size} : Positive := 5});
@end deftypefn
@fnindex Sockets.Listen

@item Parameters
@multitable {XXXXXXXX} {in out X} {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
@item @var{Socket} @tab in @tab Initialized and bound socket object
@item @var{Queue_Size} @tab in @tab Requested slots in the listen queue
@end multitable


@item Description
This procedure establishes a listen queue after a TCP socket as been
initialized and bound. Each slot in the queue can hold one
incoming connection that has not been accepted yet. Note that
most operating systems ignore queue sizes larger than five.




@item See also
@ref{Accept_Socket (procedure)},@*@ref{Bind (procedure)},@*@ref{Socket (procedure)}.

@end table

@node New_Line (procedure)
@unnumberedsubsec New_Line (procedure)
@cindex Sending data

@table @sc
@item Purpose
Send a CR/LF to a remote host
@item Prototype
@deftypefn Sockets.New_Line procedure New_Line (@w{@var{Socket} : Socket_FD'Class}; @w{@var{Count} : Natural := 1});
@end deftypefn
@fnindex Sockets.New_Line

@item Parameters
@multitable {XXXXXXXX} {in out X} {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
@item @var{Socket} @tab in @tab Initialized and connected socket object
@item @var{Count} @tab in @tab Number of CR/LF sequences to send
@end multitable


@item Description
@ctindex CR
@ctindex LF
This procedure sends one or more CR/LF combinations to the peer.


@item Exceptions
@multitable {XXXXXXXXXXXXXXXX} {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
@item @code{Connection_Closed} @tab Peer has prematurely closed the connection@exindex Connection_Closed
@end multitable





@item See also
@ref{Put (procedure)},@*@ref{Put_Line (procedure)}.

@end table

@node Put (procedure)
@unnumberedsubsec Put (procedure)
@cindex Sending data

@table @sc
@item Purpose
Send a string to a remote host
@item Prototype
@deftypefn Sockets.Put procedure Put (@w{@var{Socket} : Socket_FD'Class}; @w{@var{Str} : String});
@end deftypefn
@fnindex Sockets.Put

@item Parameters
@multitable {XXXXXXXX} {in out X} {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
@item @var{Socket} @tab in @tab Initialized and connected socket object
@item @var{Str} @tab in @tab String to send
@end multitable


@item Description
This procedure sends the content of @var{Str} over an outgoing
or incoming socket.


@item Exceptions
@multitable {XXXXXXXXXXXXXXXX} {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
@item @code{Connection_Closed} @tab Peer has prematurely closed the connection@exindex Connection_Closed
@end multitable





@item See also
@ref{New_Line (procedure)},@*@ref{Put_Line (procedure)},@*@ref{Send (procedure)}.

@end table

@node Put_Line (procedure)
@unnumberedsubsec Put_Line (procedure)
@cindex Sending data

@table @sc
@item Purpose
Send a CR/LF terminated string to a remote host
@item Prototype
@deftypefn Sockets.Put_Line procedure Put_Line (@w{@var{Socket} : Socket_FD'Class}; @w{@var{Str} : String});
@end deftypefn
@fnindex Sockets.Put_Line

@item Parameters
@multitable {XXXXXXXX} {in out X} {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
@item @var{Socket} @tab in @tab Initialized and connected socket object
@item @var{Str} @tab in @tab String to send
@end multitable


@item Description
This procedure sends the content of @var{Str} plus a CR/LF combination
over an outgoing or incoming socket.


@item Exceptions
@multitable {XXXXXXXXXXXXXXXX} {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
@item @code{Connection_Closed} @tab Peer has prematurely closed the connection@exindex Connection_Closed
@end multitable





@item See also
@ref{New_Line (procedure)},@*@ref{Put (procedure)},@*@ref{Send (procedure)}.

@end table

@node Receive (function)
@unnumberedsubsec Receive (function)
@cindex Receiving data

@table @sc
@item Purpose
Receive raw data over a socket
@item Prototype
@deftypefn Sockets.Receive function Receive (@w{@var{Socket} : Socket_FD}; @w{@var{Max} : Ada.Streams.Stream_Element_Count := 4096})@*@w{return Ada.Streams.Stream_Element_Array;}
@end deftypefn
@fnindex Sockets.Receive

@item Parameters
@multitable {XXXXXXXX} {in out X} {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
@item @var{Socket} @tab in @tab Initialized and bound or connected socket object
@item @var{Max} @tab in @tab Maximum data length
@end multitable

@item Return value
Received raw data

@item Description
@tindex Ada.Streams.Stream_Element_Count
@tindex Ada.Streams.Stream_Element_Array
@tindex Stream_Element_Count
@tindex Stream_Element_Array
This procedure receives data from a bound UDP socket or a connected
TCP socket. Only one system call will be performed; this
function will return whatever data has arrived. Note that in
GNAT the secondary stack may be used to store  the data and may
result in stack storage exhaustion.


@item Exceptions
@multitable {XXXXXXXXXXXXXXXX} {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
@item @code{Connection_Closed} @tab Peer has closed the connection before sending any data@exindex Connection_Closed
@end multitable





@item See also
@ref{Receive (procedure)},@*@ref{Receive_Some (procedure)},@*@ref{Get_Line (function)},@*@ref{Get_Line (procedure)}.

@end table

@node Receive (procedure)
@unnumberedsubsec Receive (procedure)
@cindex Receiving data

@table @sc
@item Purpose
Receive raw data over a socket
@item Prototype
@deftypefn Sockets.Receive procedure Receive (@w{@var{Socket} : Socket_FD'Class}; @w{@var{Data} : out Ada.Streams.Stream_Element_Array});
@end deftypefn
@fnindex Sockets.Receive

@item Parameters
@multitable {XXXXXXXX} {in out X} {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
@item @var{Socket} @tab in @tab Initialized and bound or connected socket object
@item @var{Data} @tab out @tab Incoming data buffer
@end multitable


@item Description
@tindex Ada.Streams.Stream_Element_Array
@tindex Stream_Element_Array
This procedure receives data from a bound UDP socket or a connected
TCP socket. It will block until the @var{Data} reception buffer
has been totally filled.


@item Exceptions
@multitable {XXXXXXXXXXXXXXXX} {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
@item @code{Connection_Closed} @tab Peer has closed the connection before @code{Data'Length} bytes@*
were received@exindex Connection_Closed
@end multitable





@item See also
@ref{Get_Line (function)},@*@ref{Get_Line (procedure)},@*@ref{Receive (function)},@*@ref{Receive_Some (procedure)}.

@end table

@node Receive_Some (procedure)
@unnumberedsubsec Receive_Some (procedure)
@cindex Receiving data

@table @sc
@item Purpose
Receive raw data over a socket
@item Prototype
@deftypefn Sockets.Receive_Some procedure Receive_Some (@w{@var{Socket} : Socket_FD'Class}; @w{@var{Data} : out Ada.Streams.Stream_Element_Array}; @w{@var{Last} : out Ada.Streams.Stream_Element_Offset});
@end deftypefn
@fnindex Sockets.Receive_Some

@item Parameters
@multitable {XXXXXXXX} {in out X} {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
@item @var{Socket} @tab in @tab Initialized and bound or connected socket object
@item @var{Data} @tab out @tab Incoming data buffer
@item @var{Last} @tab out @tab Index of last element placed into @var{Data}
@end multitable


@item Description
@tindex Ada.Streams.Stream_Element_Array
@tindex Stream_Element_Array
@tindex Ada.Streams.Stream_Element_Count
@tindex Stream_Element_Count
This procedure receives data from a bound UDP socket or a connected
TCP socket. As soon as at least one byte has been read, it returns
with @var{Last} set to the index of the latest written element
of @var{Data}.


@item Exceptions
@multitable {XXXXXXXXXXXXXXXX} {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
@item @code{Connection_Closed} @tab Peer has closed the connection before sending any data@exindex Connection_Closed
@end multitable





@item See also
@ref{Get_Line (function)},@*@ref{Get_Line (procedure)},@*@ref{Receive (function)},@*@ref{Receive (procedure)}.

@end table

@node Send (procedure)
@unnumberedsubsec Send (procedure)
@cindex Sending data

@table @sc
@item Purpose
Send raw data over a socket
@item Prototype
@deftypefn Sockets.Send procedure Send (@w{@var{Socket} : Socket_FD}; @w{@var{Data} : out Ada.Streams.Stream_Element_Array});
@end deftypefn
@fnindex Sockets.Send

@item Parameters
@multitable {XXXXXXXX} {in out X} {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
@item @var{Socket} @tab in @tab Initialized and connected socket object
@item @var{Data} @tab out @tab Data to be sent
@end multitable


@item Description
@tindex Ada.Streams.Stream_Element_Array
@tindex Stream_Element_Array
This procedure sends data over a connected outgoing socket or
over an incoming socket.


@item Exceptions
@multitable {XXXXXXXXXXXXXXXX} {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
@item @code{Connection_Closed} @tab Peer has prematurely closed the connection@exindex Connection_Closed
@end multitable





@item See also
@ref{Put (procedure)},@*@ref{Put_Line (procedure)}.

@end table

@node Set_Buffer (procedure)
@unnumberedsubsec Set_Buffer (procedure)
@cindex Receiving data

@table @sc
@item Purpose
Install a line-oriented buffer of the socket object
@item Prototype
@deftypefn Sockets.Set_Buffer procedure Set_Buffer (@w{@var{Socket} : Socket_FD'Class}; @w{@var{Length} : Positive := 1500});
@end deftypefn
@fnindex Sockets.Set_Buffer

@item Parameters
@multitable {XXXXXXXX} {in out X} {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
@item @var{Socket} @tab in @tab Initialized and connected socket object
@item @var{Length} @tab in @tab Size in bytes of the newly installed buffer
@end multitable


@item Description
This procedure puts the socket object in buffered mode. If the
socket was already buffered, the content of the previous buffer
will be lost. The buffered mode only affects character- and
line-oriented read operation such as @ref{Get (function)},
@ref{Get_Char (function)}, and @ref{Get_Line (function)}. Other
reception subprograms will not function properly if buffered mode
is used at the same time.

The size of the buffer has to be greater than the biggest
possible packet sent by the remote host, otherwise data loss may
occur.




@item See also
@ref{Unset_Buffer (procedure)}.

@end table

@node Setsockopt (procedure)
@unnumberedsubsec Setsockopt (procedure)
@cindex Manipulating socket options
@cindex Setting socket options

@table @sc
@item Purpose
Set a socket option
@item Prototype
@deftypefn Sockets.Setsockopt procedure Setsockopt (@w{@var{Socket} : Socket_FD}; @w{@var{Level} : Socket_Level := SOL_SOCKET}; @w{@var{Optname} : Socket_Option}; @w{@var{Optval} : Integer});
@end deftypefn
@fnindex Sockets.Setsockopt

@item Parameters
@multitable {XXXXXXXX} {in out X} {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
@item @var{Socket} @tab in @tab Initialized and bound socket object
@item @var{Level} @tab in @tab Protocol level
@item @var{Optname} @tab in @tab Option name
@item @var{Optval} @tab in @tab Option value
@end multitable


@item Description
@ctindex Sockets.SOL_SOCKET
@ctindex Sockets.IPPROTO_IP
@ctindex Sockets.SO_REUSEADDR
@ctindex Sockets.SO_REUSEPORT
@ctindex Sockets.IP_MULTICAST_TTL
@ctindex Sockets.IP_ADD_MEMBERSHIP
@ctindex Sockets.IP_DROP_MEMBERSHIP
@ctindex Sockets.IP_MULTICAST_LOOP
@ctindex Sockets.SO_SNDBUF
@ctindex Sockets.SO_RCVBUF
@ctindex SOL_SOCKET
@ctindex IPPROTO_IP
@ctindex SO_REUSEADDR
@ctindex SO_REUSEPORT
@ctindex IP_MULTICAST_TTL
@ctindex IP_ADD_MEMBERSHIP
@ctindex IP_DROP_MEMBERSHIP
@ctindex IP_MULTICAST_LOOP
@ctindex SO_SNDBUF
@ctindex SO_RCVBUF
This procedure sets options applicable to a socket. Please
see your operating system manual for usable levels and options.

Two levels are defined: @code{SOL_SOCKET} (the default) and
@code{IPPROTO_IP}. The options are @code{SO_REUSEADDR},
@code{SO_REUSEPORT}, @code{IP_MULTICAST_TTL},
@code{IP_ADD_MEMBERSHIP}, @code{IP_DROP_MEMBERSHIP},
@code{IP_MULTICAST_LOOP}, @code{SO_SNDBUF} and
@code{IP_RCVBUF}.

Note that unlike their C language counterpart, @code{Getsockopt}
and @code{Setsockopt} do not require an extra parameter
representing the length in bytes of the option value. AdaSockets
nows the right size for every option.




@item See also
@ref{Getsockopt (procedure)}.

@end table

@node Shutdown (procedure)
@unnumberedsubsec Shutdown (procedure)
@cindex Closing a socket
@cindex Socket shutdown

@table @sc
@item Purpose
Shutdown a socket
@item Prototype
@deftypefn Sockets.Shutdown procedure Shutdown (@w{@var{Socket} : in out Socket_FD}; @w{@var{How} : Shutdown_Type := Both});
@end deftypefn
@fnindex Sockets.Shutdown

@item Parameters
@multitable {XXXXXXXX} {in out X} {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
@item @var{Socket} @tab in out @tab Socket object to shutdown
@item @var{How} @tab in @tab Direction to shutdown
@end multitable


@item Description
@ctindex Send
@ctindex Receive
@ctindex Both
This procedure shutdowns either direction of the socket. @var{How}
can take the value @samp{Send}, @samp{Receive} or @samp{Both}.




@item See also
@ref{Socket (procedure)}.

@end table

@node Socket (procedure)
@unnumberedsubsec Socket (procedure)
@cindex Creating a socket

@table @sc
@item Purpose
Create a socket of the given mode
@item Prototype
@deftypefn Sockets.Socket procedure Socket (@w{@var{Socket} : out Socket_FD}; @w{@var{Domain} : Socket_Domain := PF_INET}; @w{@var{Typ} : Socket_Type := SOCK_STREAM});
@end deftypefn
@fnindex Sockets.Socket

@item Parameters
@multitable {XXXXXXXX} {in out X} {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
@item @var{Socket} @tab out @tab Socket object to initialize
@item @var{Domain} @tab in @tab Protocol family
@item @var{Typ} @tab in @tab Kind of sockets
@end multitable


@item Description
@ctindex PF_INET
@ctindex AF_INET
@ctindex SOCK_STREAM
@ctindex SOCK_DGRAM
This procedure initializes a new socket object by reserving a file
descriptor to the operating system. For backward compatibility with
older versions of this library, @code{AF_INET} is still accepted as
a value but should be replaced as soon as possible with the proper
@code{PF_INET}. Using @code{SOCK_STREAM} for the @var{Typ}
argument will create a TCP socket while a @code{SOCK_DGRAM} will
create a UDP one.



@item Example
@example
declare
   Sock : Socket_FD;
begin
   -- Create a TCP socket
   Socket (Sock, PF_INET, SOCK_STREAM);
   -- Perform some operations on socket
   [...]
   -- Shutdown the socket in both directions
   Shutdown (Sock, Both);
end;
@end example


@item See also
@ref{Shutdown (procedure)}.

@end table

@node Unset_Buffer (procedure)
@unnumberedsubsec Unset_Buffer (procedure)
@cindex Receiving data

@table @sc
@item Purpose
Deinstall the line-oriented buffer of the socket object
@item Prototype
@deftypefn Sockets.Unset_Buffer procedure Unset_Buffer (@w{@var{Socket} : Socket_FD'Class});
@end deftypefn
@fnindex Sockets.Unset_Buffer

@item Parameters
@multitable {XXXXXXXX} {in out X} {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
@item @var{Socket} @tab in @tab Initialized and connected socket object
@end multitable


@item Description
This procedure deinstalls the buffer previously installed by
@ref{Set_Buffer (procedure)}. If any data is still present in
the buffer, it will be lost. To avoid this situation, the buffer
can be flushed by calling @ref{Get (function)}.




@end table