-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathbuffers.tex
1501 lines (1200 loc) · 48.5 KB
/
buffers.tex
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
%!TEX root = ts.tex
\rSec0[buffer]{Buffers}
\indexlibrary{\idxhdr{experimental/buffer}}%
\rSec1[buffer.synop]{Header \tcode{<experimental/buffer>} synopsis}
\indexlibrary{\idxcode{is_mutable_buffer_sequence_v}}%
\indexlibrary{\idxcode{is_const_buffer_sequence_v}}%
\indexlibrary{\idxcode{is_dynamic_buffer_v}}%
\indexlibrary{\idxcode{stream_errc}}%
\begin{codeblock}
namespace std {
namespace experimental {
namespace net {
inline namespace v1 {
enum class stream_errc {
eof = @\EXPO{an \impldef{value of \tcode{stream_errc::eof}} non-zero value}@,
not_found = @\EXPO{an \impldef{value of \tcode{stream_errc::not_found}} non-zero value}@
};
const error_category& stream_category() noexcept;
error_code make_error_code(stream_errc e) noexcept;
error_condition make_error_condition(stream_errc e) noexcept;
class mutable_buffer;
class const_buffer;
// \ref{buffer.traits}, buffer type traits
template<class T> struct is_mutable_buffer_sequence;
template<class T> struct is_const_buffer_sequence;
template<class T> struct is_dynamic_buffer;
template<class T>
constexpr bool is_mutable_buffer_sequence_v = is_mutable_buffer_sequence<T>::value;
template<class T>
constexpr bool is_const_buffer_sequence_v = is_const_buffer_sequence<T>::value;
template<class T>
constexpr bool is_dynamic_buffer_v = is_dynamic_buffer<T>::value;
// \ref{buffer.seq.access}, buffer sequence access
const mutable_buffer* buffer_sequence_begin(const mutable_buffer& b) noexcept;
const const_buffer* buffer_sequence_begin(const const_buffer& b) noexcept;
const mutable_buffer* buffer_sequence_end(const mutable_buffer& b) noexcept;
const const_buffer* buffer_sequence_end(const const_buffer& b) noexcept;
template<class C> auto buffer_sequence_begin(C& c) noexcept -> decltype(c.begin());
template<class C> auto buffer_sequence_begin(const C& c) noexcept -> decltype(c.begin());
template<class C> auto buffer_sequence_end(C& c) noexcept -> decltype(c.end());
template<class C> auto buffer_sequence_end(const C& c) noexcept -> decltype(c.end());
// \ref{buffer.size}, buffer size
template<class ConstBufferSequence>
size_t buffer_size(const ConstBufferSequence& buffers) noexcept;
// \ref{buffer.copy}, buffer copy
template<class MutableBufferSequence, class ConstBufferSequence>
size_t buffer_copy(const MutableBufferSequence& dest,
const ConstBufferSequence& source) noexcept;
template<class MutableBufferSequence, class ConstBufferSequence>
size_t buffer_copy(const MutableBufferSequence& dest,
const ConstBufferSequence& source,
size_t max_size) noexcept;
// \ref{buffer.arithmetic}, buffer arithmetic
mutable_buffer operator+(const mutable_buffer& b, size_t n) noexcept;
mutable_buffer operator+(size_t n, const mutable_buffer& b) noexcept;
const_buffer operator+(const const_buffer&, size_t n) noexcept;
const_buffer operator+(size_t, const const_buffer&) noexcept;
// \ref{buffer.creation}, buffer creation
mutable_buffer buffer(void* p, size_t n) noexcept;
const_buffer buffer(const void* p, size_t n) noexcept;
mutable_buffer buffer(const mutable_buffer& b) noexcept;
mutable_buffer buffer(const mutable_buffer& b, size_t n) noexcept;
const_buffer buffer(const const_buffer& b) noexcept;
const_buffer buffer(const const_buffer& b, size_t n) noexcept;
template<class T, size_t N>
mutable_buffer buffer(T (&data)[N]) noexcept;
template<class T, size_t N>
const_buffer buffer(const T (&data)[N]) noexcept;
template<class T, size_t N>
mutable_buffer buffer(array<T, N>& data) noexcept;
template<class T, size_t N>
const_buffer buffer(array<const T, N>& data) noexcept;
template<class T, size_t N>
const_buffer buffer(const array<T, N>& data) noexcept;
template<class T, class Allocator>
mutable_buffer buffer(vector<T, Allocator>& data) noexcept;
template<class T, class Allocator>
const_buffer buffer(const vector<T, Allocator>& data) noexcept;
template<class CharT, class Traits, class Allocator>
mutable_buffer buffer(basic_string<CharT, Traits, Allocator>& data) noexcept;
template<class CharT, class Traits, class Allocator>
const_buffer buffer(const basic_string<CharT, Traits, Allocator>& data) noexcept;
template<class CharT, class Traits>
const_buffer buffer(basic_string_view<CharT, Traits> data) noexcept;
template<class T, size_t N>
mutable_buffer buffer(T (&data)[N], size_t n) noexcept;
template<class T, size_t N>
const_buffer buffer(const T (&data)[N], size_t n) noexcept;
template<class T, size_t N>
mutable_buffer buffer(array<T, N>& data, size_t n) noexcept;
template<class T, size_t N>
const_buffer buffer(array<const T, N>& data, size_t n) noexcept;
template<class T, size_t N>
const_buffer buffer(const array<T, N>& data, size_t n) noexcept;
template<class T, class Allocator>
mutable_buffer buffer(vector<T, Allocator>& data, size_t n) noexcept;
template<class T, class Allocator>
const_buffer buffer(const vector<T, Allocator>& data, size_t n) noexcept;
template<class CharT, class Traits, class Allocator>
mutable_buffer buffer(basic_string<CharT, Traits, Allocator>& data,
size_t n) noexcept;
template<class CharT, class Traits, class Allocator>
const_buffer buffer(const basic_string<CharT, Traits, Allocator>& data,
size_t n) noexcept;
template<class CharT, class Traits>
const_buffer buffer(basic_string_view<CharT, Traits> data,
size_t n) noexcept;
template<class T, class Allocator>
class dynamic_vector_buffer;
template<class CharT, class Traits, class Allocator>
class dynamic_string_buffer;
// \ref{buffer.dynamic.creation}, dynamic buffer creation
template<class T, class Allocator>
dynamic_vector_buffer<T, Allocator>
dynamic_buffer(vector<T, Allocator>& vec) noexcept;
template<class T, class Allocator>
dynamic_vector_buffer<T, Allocator>
dynamic_buffer(vector<T, Allocator>& vec, size_t n) noexcept;
template<class CharT, class Traits, class Allocator>
dynamic_string_buffer<CharT, Traits, Allocator>
dynamic_buffer(basic_string<CharT, Traits, Allocator>& str) noexcept;
template<class CharT, class Traits, class Allocator>
dynamic_string_buffer<CharT, Traits, Allocator>
dynamic_buffer(basic_string<CharT, Traits, Allocator>& str, size_t n) noexcept;
class transfer_all;
class transfer_at_least;
class transfer_exactly;
// \ref{buffer.read}, synchronous read operations
template<class SyncReadStream, class MutableBufferSequence>
size_t read(SyncReadStream& stream,
const MutableBufferSequence& buffers);
template<class SyncReadStream, class MutableBufferSequence>
size_t read(SyncReadStream& stream,
const MutableBufferSequence& buffers, error_code& ec);
template<class SyncReadStream, class MutableBufferSequence,
class CompletionCondition>
size_t read(SyncReadStream& stream,
const MutableBufferSequence& buffers,
CompletionCondition completion_condition);
template<class SyncReadStream, class MutableBufferSequence,
class CompletionCondition>
size_t read(SyncReadStream& stream,
const MutableBufferSequence& buffers,
CompletionCondition completion_condition,
error_code& ec);
template<class SyncReadStream, class DynamicBuffer>
size_t read(SyncReadStream& stream, DynamicBuffer&& b);
template<class SyncReadStream, class DynamicBuffer>
size_t read(SyncReadStream& stream, DynamicBuffer&& b, error_code& ec);
template<class SyncReadStream, class DynamicBuffer, class CompletionCondition>
size_t read(SyncReadStream& stream, DynamicBuffer&& b,
CompletionCondition completion_condition);
template<class SyncReadStream, class DynamicBuffer, class CompletionCondition>
size_t read(SyncReadStream& stream, DynamicBuffer&& b,
CompletionCondition completion_condition, error_code& ec);
// \ref{buffer.async.read}, asynchronous read operations
template<class AsyncReadStream, class MutableBufferSequence,
class CompletionToken>
@\DEDUCED@ async_read(AsyncReadStream& stream,
const MutableBufferSequence& buffers,
CompletionToken&& token);
template<class AsyncReadStream, class MutableBufferSequence,
class CompletionCondition, class CompletionToken>
@\DEDUCED@ async_read(AsyncReadStream& stream,
const MutableBufferSequence& buffers,
CompletionCondition completion_condition,
CompletionToken&& token);
template<class AsyncReadStream, class DynamicBuffer, class CompletionToken>
@\DEDUCED@ async_read(AsyncReadStream& stream,
DynamicBuffer&& b, CompletionToken&& token);
template<class AsyncReadStream, class DynamicBuffer,
class CompletionCondition, class CompletionToken>
@\DEDUCED@ async_read(AsyncReadStream& stream,
DynamicBuffer&& b,
CompletionCondition completion_condition,
CompletionToken&& token);
// \ref{buffer.write}, synchronous write operations
template<class SyncWriteStream, class ConstBufferSequence>
size_t write(SyncWriteStream& stream,
const ConstBufferSequence& buffers);
template<class SyncWriteStream, class ConstBufferSequence>
size_t write(SyncWriteStream& stream,
const ConstBufferSequence& buffers, error_code& ec);
template<class SyncWriteStream, class ConstBufferSequence,
class CompletionCondition>
size_t write(SyncWriteStream& stream,
const ConstBufferSequence& buffers,
CompletionCondition completion_condition);
template<class SyncWriteStream, class ConstBufferSequence,
class CompletionCondition>
size_t write(SyncWriteStream& stream,
const ConstBufferSequence& buffers,
CompletionCondition completion_condition,
error_code& ec);
template<class SyncWriteStream, class DynamicBuffer>
size_t write(SyncWriteStream& stream, DynamicBuffer&& b);
template<class SyncWriteStream, class DynamicBuffer>
size_t write(SyncWriteStream& stream, DynamicBuffer&& b, error_code& ec);
template<class SyncWriteStream, class DynamicBuffer, class CompletionCondition>
size_t write(SyncWriteStream& stream, DynamicBuffer&& b,
CompletionCondition completion_condition);
template<class SyncWriteStream, class DynamicBuffer, class CompletionCondition>
size_t write(SyncWriteStream& stream, DynamicBuffer&& b,
CompletionCondition completion_condition, error_code& ec);
// \ref{buffer.async.write}, asynchronous write operations
template<class AsyncWriteStream, class ConstBufferSequence,
class CompletionToken>
@\DEDUCED@ async_write(AsyncWriteStream& stream,
const ConstBufferSequence& buffers,
CompletionToken&& token);
template<class AsyncWriteStream, class ConstBufferSequence,
class CompletionCondition, class CompletionToken>
@\DEDUCED@ async_write(AsyncWriteStream& stream,
const ConstBufferSequence& buffers,
CompletionCondition completion_condition,
CompletionToken&& token);
template<class AsyncWriteStream, class DynamicBuffer, class CompletionToken>
@\DEDUCED@ async_write(AsyncWriteStream& stream,
DynamicBuffer&& b, CompletionToken&& token);
template<class AsyncWriteStream, class DynamicBuffer,
class CompletionCondition, class CompletionToken>
@\DEDUCED@ async_write(AsyncWriteStream& stream,
DynamicBuffer&& b,
CompletionCondition completion_condition,
CompletionToken&& token);
// \ref{buffer.read.until}, synchronous delimited read operations
template<class SyncReadStream, class DynamicBuffer>
size_t read_until(SyncReadStream& s, DynamicBuffer&& b, char delim);
template<class SyncReadStream, class DynamicBuffer>
size_t read_until(SyncReadStream& s, DynamicBuffer&& b,
char delim, error_code& ec);
template<class SyncReadStream, class DynamicBuffer>
size_t read_until(SyncReadStream& s, DynamicBuffer&& b, string_view delim);
template<class SyncReadStream, class DynamicBuffer>
size_t read_until(SyncReadStream& s, DynamicBuffer&& b,
string_view delim, error_code& ec);
// \ref{buffer.async.read.until}, asynchronous delimited read operations
template<class AsyncReadStream, class DynamicBuffer, class CompletionToken>
@\DEDUCED@ async_read_until(AsyncReadStream& s,
DynamicBuffer&& b, char delim,
CompletionToken&& token);
template<class AsyncReadStream, class DynamicBuffer, class CompletionToken>
@\DEDUCED@ async_read_until(AsyncReadStream& s,
DynamicBuffer&& b, string_view delim,
CompletionToken&& token);
} // inline namespace v1
} // namespace net
} // namespace experimental
template<> struct is_error_code_enum<experimental::net::v1::stream_errc>
: public true_type {};
} // namespace std
\end{codeblock}
\rSec1[buffer.reqmts]{Requirements}
\rSec2[buffer.reqmts.mutablebuffersequence]{Mutable buffer sequence requirements}
\pnum
A \defn{mutable buffer sequence} represents a set of memory regions that may be used to receive the output of an operation, such as the \tcode{receive} operation of a socket.
\pnum
A type \tcode{X} meets the \tcode{MutableBufferSequence} requirements if it satisfies the requirements of \tcode{Destructible} (\CppXref{destructible}) and \tcode{CopyConstructible} (\CppXref{copyconstructible}), as well as the additional requirements listed in Table~\ref{tab:buffer.reqmts.mutablebuffersequence.requirements}.
\pnum
In Table~\ref{tab:buffer.reqmts.mutablebuffersequence.requirements},
\tcode{x} denotes a (possibly const) value of type \tcode{X},
and \tcode{u} denotes an identifier.
\indextext{requirements!\idxcode{MutableBufferSequence}}%
\begin{LongTable}
{MutableBufferSequence requirements}
{tab:buffer.reqmts.mutablebuffersequence.requirements}
{x{.27\hsize}x{.23\hsize}x{.40\hsize}}
\\ \topline
\lhdr{expression} &
\chdr{return type} &
\rhdr{assertion/note} \\
\lhdr{} &
\chdr{} &
\rhdr{pre/post-condition} \\ \capsep
\endfirsthead
\continuedcaption\\
\hline
\lhdr{expression} &
\chdr{return type} &
\rhdr{assertion/note} \\
\lhdr{} &
\chdr{} &
\rhdr{pre/post-condition} \\ \capsep
\endhead
\tcode{net::buffer_sequence_begin(x)}\br
\tcode{net::buffer_sequence_end(x)} &
An iterator type whose \tcode{reference} type is convertible to \tcode{mutable_buffer},
and which satisfies all the requirements for bidirectional iterators (\CppXref{bidirectional.iterators})
except that:
\begin{itemize}
\item there is no requirement that \tcode{operator->} is provided, and
\item there is no requirement that \tcode{reference} be a reference type.
\end{itemize} &
For a dereferenceable iterator, no increment, decrement, or dereference operation, or conversion of the reference type to \tcode{mutable_buffer}, shall exit via an exception.
\\ \rowsep
\tcode{X u(x);}
&
&
post: \begin{codeblock}
equal(
net::buffer_sequence_begin(x),
net::buffer_sequence_end(x),
net::buffer_sequence_begin(u),
net::buffer_sequence_end(u),
[](const mutable_buffer& b1,
const mutable_buffer& b2)
{
return b1.data() == b2.data()
&& b1.size() == b2.size();
})
\end{codeblock}
\\
\end{LongTable}
\rSec2[buffer.reqmts.constbuffersequence]{Constant buffer sequence requirements}
\pnum
A \defn{constant buffer sequence} represents a set of memory regions that may be used as input to an operation, such as the \tcode{send} operation of a socket.
\pnum
A type \tcode{X} meets the \tcode{ConstBufferSequence} requirements if it satisfies the requirements of \tcode{Destructible} (\CppXref{destructible}) and \tcode{CopyConstructible} (\CppXref{copyconstructible}), as well as the additional requirements listed in Table~\ref{tab:buffer.reqmts.constbuffersequence.requirements}.
\pnum
In Table~\ref{tab:buffer.reqmts.constbuffersequence.requirements},
\tcode{x} denotes a (possibly const) value of type \tcode{X},
and \tcode{u} denotes an identifier.
\indextext{requirements!\idxcode{ConstBufferSequence}}%
\begin{LongTable}
{ConstBufferSequence requirements}
{tab:buffer.reqmts.constbuffersequence.requirements}
{x{.27\hsize}x{.22\hsize}x{.40\hsize}}
\\ \topline
\lhdr{expression} &
\chdr{return type} &
\rhdr{assertion/note} \\
\lhdr{} &
\chdr{} &
\rhdr{pre/post-condition} \\ \capsep
\endfirsthead
\continuedcaption\\
\hline
\lhdr{expression} &
\chdr{return type} &
\rhdr{assertion/note} \\
\lhdr{} &
\chdr{} &
\rhdr{pre/post-condition} \\ \capsep
\endhead
\tcode{net::buffer_sequence_begin(x)}\br
\tcode{net::buffer_sequence_end(x)} &
An iterator type whose \tcode{reference} type is convertible to \tcode{const_buffer},
and which satisfies all the requirements for bidirectional iterators (\CppXref{bidirectional.iterators})
except that:
\begin{itemize}
\item there is no requirement that \tcode{operator->} is provided, and
\item there is no requirement that \tcode{reference} be a reference type.
\end{itemize} &
For a dereferenceable iterator, no increment, decrement, or dereference operation, or conversion of the reference type to \tcode{const_buffer}, shall exit via an exception.
\\ \rowsep
\tcode{X u(x);}
&
&
post:
\begin{codeblock}
equal(
net::buffer_sequence_begin(x),
net::buffer_sequence_end(x),
net::buffer_sequence_begin(u),
net::buffer_sequence_end(u),
[](const const_buffer& b1,
const const_buffer& b2)
{
return b1.data() == b2.data()
&& b1.size() == b2.size();
})
\end{codeblock}
\\
\end{LongTable}
\rSec2[buffer.reqmts.size]{Buffer size}
\pnum
Several places in this document make unqualified calls to \tcode{buffer_size}.
The context in which these calls are evaluated shall ensure that
a unary non-member function named \tcode{buffer_size}
is selected via overload resolution (\CppXref{over.match})
on a candidate set that includes:
\begin{itemize}
\item the \tcode{buffer_size} function template defined in \tcode{<experimental/buffer>} (\ref{buffer.synop}) and
\item the lookup set produced by argument-dependent lookup (\CppXref{basic.lookup.argdep}).
\end{itemize}
\rSec2[buffer.reqmts.dynamicbuffer]{Dynamic buffer requirements}
\pnum
A \defn{dynamic buffer} encapsulates memory storage that may be automatically resized as required, where the memory is divided into two regions: readable bytes followed by writable bytes. These memory regions are internal to the dynamic buffer, but direct access to the elements is provided to permit them to be efficiently used with I/O operations. \begin{note} Such as the \tcode{send} or \tcode{receive} operations of a socket. The readable bytes would be used as the constant buffer sequence for \tcode{send}, and the writable bytes used as the mutable buffer sequence for \tcode{receive}. \end{note} Data written to the writable bytes of a dynamic buffer object is appended to the readable bytes of the same object.
\pnum
A type \tcode{X} meets the \tcode{DynamicBuffer} requirements if it satisfies the requirements of \tcode{Destructible} (\CppXref{destructible}) and \tcode{MoveConstructible} (\CppXref{moveconstructible}), as well as the additional requirements listed in Table~\ref{tab:buffer.reqmts.dynamicbuffer.requirements}.
\pnum
In Table~\ref{tab:buffer.reqmts.dynamicbuffer.requirements},
\tcode{x} denotes a value of type \tcode{X},
\tcode{x1} denotes a (possibly const) value of type \tcode{X},
and \tcode{n} denotes a (possibly const) value of type \tcode{size_t}.
\indextext{requirements!\idxcode{DynamicBuffer}}%
\begin{libreqtab3}
{DynamicBuffer requirements}
{tab:buffer.reqmts.dynamicbuffer.requirements}
\\ \topline
\lhdr{expression} &
\chdr{type} &
\rhdr{assertion/note pre/post-conditions} \\ \capsep
\endfirsthead
\continuedcaption\\
\hline
\lhdr{expression} &
\chdr{type} &
\rhdr{assertion/note pre/post-conditions} \\ \capsep
\endhead
\tcode{X::const_buffers_type} &
type meeting ConstBufferSequence~(\ref{buffer.reqmts.constbuffersequence}) requirements. &
This type represents the memory associated with the readable bytes. \\ \rowsep
\tcode{X::mutable_buffers_type} &
type meeting MutableBufferSequence~(\ref{buffer.reqmts.constbuffersequence}) requirements. &
This type represents the memory associated with the writable bytes. \\ \rowsep
\tcode{x1.size()} &
\tcode{size_t} &
Returns the number of readable bytes. \\ \rowsep
\tcode{x1.max_size()} &
\tcode{size_t} &
Returns the maximum number of bytes, both readable and writable, that can be held by \tcode{x1}. \\ \rowsep
\tcode{x1.capacity()} &
\tcode{size_t} &
Returns the maximum number of bytes, both readable and writable, that can be held by \tcode{x1} without requiring reallocation. \\ \rowsep
\tcode{x1.data()} &
\tcode{X::const_buffers_type} &
Returns a constant buffer sequence \tcode{u} that represents the readable bytes, and where \tcode{buffer_size(u) == size()}. \\ \rowsep
\tcode{x.prepare(n)} &
\tcode{X::mutable_buffers_type} &
Returns a mutable buffer sequence \tcode{u} representing the writable bytes, and where \tcode{buffer_size(u) == n}. The dynamic buffer reallocates memory as required. All constant or mutable buffer sequences previously obtained using \tcode{data()} or \tcode{prepare()} are invalidated.\br \throws\ \tcode{length_error} if \tcode{size() + n} exceeds \tcode{max_size()}. \\ \rowsep
\tcode{x.commit(n)} &
&
Appends \tcode{n} bytes from the start of the writable bytes to the end of the readable bytes. The remainder of the writable bytes are discarded. If \tcode{n} is greater than the number of writable bytes, all writable bytes are appended to the readable bytes. All constant or mutable buffer sequences previously obtained using \tcode{data()} or \tcode{prepare()} are invalidated. \\ \rowsep
\tcode{x.consume(n)} &
&
Removes \tcode{n} bytes from beginning of the readable bytes. If \tcode{n} is greater than the number of readable bytes, all readable bytes are removed. All constant or mutable buffer sequences previously obtained using \tcode{data()} or \tcode{prepare()} are invalidated. \\
\end{libreqtab3}
\rSec2[buffer.reqmts.read.write]{Requirements on read and write operations}
\pnum
A \defn{read operation} is an operation that reads data into a mutable buffer sequence argument of a type meeting \tcode{MutableBufferSequence}~(\ref{buffer.reqmts.mutablebuffersequence}) requirements. The mutable buffer sequence specifies memory where the data should be placed. A read operation shall always fill a buffer in the sequence completely before proceeding to the next.
\pnum
A \defn{write operation} is an operation that writes data from a constant buffer sequence argument of a type meeting \tcode{ConstBufferSequence}~(\ref{buffer.reqmts.constbuffersequence}) requirements. The constant buffer sequence specifies memory where the data to be written is located. A write operation shall always write a buffer in the sequence completely before proceeding to the next.
\indextext{asynchronous operation}%
\pnum
If a read or write operation is also an asynchronous operation~(\ref{async.reqmts.async}), the operation shall maintain one or more copies of the buffer sequence until such time as the operation no longer requires access to the memory specified by the buffers in the sequence. The program shall ensure the memory remains valid until:
\begin{itemize}
\item the last copy of the buffer sequence is destroyed, or
\item the completion handler for the asynchronous operation is invoked,
\end{itemize}
whichever comes first.
\indextext{error codes!stream}%
\rSec1[buffer.err]{Error codes}
\indexlibrary{\idxcode{stream_category}}%
\begin{itemdecl}
const error_category& stream_category() noexcept;
\end{itemdecl}
\begin{itemdescr}
\pnum
\returns A reference to an object of a type derived from class \tcode{error_category}. All calls to this function return references to the same object.
\pnum
The object's \tcode{default_error_condition} and \tcode{equivalent} virtual functions behave as specified for the class \tcode{error_category}. The object's \tcode{name} virtual function returns a pointer to the string \tcode{"stream"}.
\end{itemdescr}
\indexlibrarymember{make_error_code}{stream_errc}%
\begin{itemdecl}
error_code make_error_code(stream_errc e) noexcept;
\end{itemdecl}
\begin{itemdescr}
\pnum
\returns \tcode{error_code(static_cast<int>(e), stream_category())}.
\end{itemdescr}
\indexlibrarymember{make_error_condition}{stream_errc}%
\begin{itemdecl}
error_condition make_error_condition(stream_errc e) noexcept;
\end{itemdecl}
\begin{itemdescr}
\pnum
\returns \tcode{error_condition(static_cast<int>(e), stream_category())}.
\end{itemdescr}
\rSec1[buffer.mutable]{Class \tcode{mutable_buffer}}
\indexlibrary{\idxcode{mutable_buffer}}%
\begin{codeblock}
namespace std {
namespace experimental {
namespace net {
inline namespace v1 {
class mutable_buffer
{
public:
// constructors:
mutable_buffer() noexcept;
mutable_buffer(void* p, size_t n) noexcept;
// members:
void* data() const noexcept;
size_t size() const noexcept;
mutable_buffer& operator+=(size_t n) noexcept;
private:
void* data_; // \expos
size_t size_; // \expos
};
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
\end{codeblock}
\pnum
The \tcode{mutable_buffer} class satisfies the requirements of \tcode{MutableBufferSequence}~(\ref{buffer.reqmts.mutablebuffersequence}), \tcode{Default\-Cons\-tr\-uct\-ible} (\CppXref{defaultconstructible}), and \tcode{CopyAssignable} (\CppXref{copyassignable}).
\indexlibrary{\idxcode{mutable_buffer}!constructor}%
\begin{itemdecl}
mutable_buffer() noexcept;
\end{itemdecl}
\begin{itemdescr}
\pnum
\postconditions \tcode{data_ == nullptr} and \tcode{size_ == 0}.
\end{itemdescr}
\indexlibrary{\idxcode{mutable_buffer}!constructor}%
\begin{itemdecl}
mutable_buffer(void* p, size_t n) noexcept;
\end{itemdecl}
\begin{itemdescr}
\pnum
\postconditions \tcode{data_ == p} and \tcode{size_ == n}.
\end{itemdescr}
\indexlibrarymember{data}{mutable_buffer}%
\begin{itemdecl}
void* data() const noexcept;
\end{itemdecl}
\begin{itemdescr}
\pnum
\returns \tcode{data_}.
\end{itemdescr}
\indexlibrarymember{size}{mutable_buffer}%
\begin{itemdecl}
size_t size() const noexcept;
\end{itemdecl}
\begin{itemdescr}
\pnum
\returns \tcode{size_}.
\end{itemdescr}
\indexlibrarymember{operator+=}{mutable_buffer}%
\begin{itemdecl}
mutable_buffer& operator+=(size_t n) noexcept;
\end{itemdecl}
\begin{itemdescr}
\pnum
\effects Sets \tcode{data_} to \tcode{static_cast<char*>(data_) + min(n, size_)},
and then \tcode{size_} to \tcode{size_ - min(n, size_)}.
\pnum
\returns \tcode{*this}.
\end{itemdescr}
\rSec1[buffer.const]{Class \tcode{const_buffer}}
\begin{codeblock}
namespace std {
namespace experimental {
namespace net {
inline namespace v1 {
class const_buffer
{
public:
// constructors:
const_buffer() noexcept;
const_buffer(const void* p, size_t n) noexcept;
const_buffer(const mutable_buffer& b) noexcept;
// members:
const void* data() const noexcept;
size_t size() const noexcept;
const_buffer& operator+=(size_t n) noexcept;
private:
const void* data_; // \expos
size_t size_; // \expos
};
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
\end{codeblock}
\pnum
The \tcode{const_buffer} class satisfies requirements of \tcode{ConstBufferSequence}~(\ref{buffer.reqmts.constbuffersequence}), \tcode{DefaultConstructible} (\CppXref{defaultconstructible}), and \tcode{CopyAssignable} (\CppXref{copyassignable}).
\indexlibrary{\idxcode{const_buffer}!constructor}%
\begin{itemdecl}
const_buffer() noexcept;
\end{itemdecl}
\begin{itemdescr}
\pnum
\postconditions \tcode{data_ == nullptr} and \tcode{size_ == 0}.
\end{itemdescr}
\indexlibrary{\idxcode{const_buffer}!constructor}%
\begin{itemdecl}
const_buffer(const void* p, size_t n) noexcept;
\end{itemdecl}
\begin{itemdescr}
\pnum
\postconditions \tcode{data_ == p} and \tcode{size_ == n}.
\end{itemdescr}
\indexlibrary{\idxcode{const_buffer}!constructor}%
\begin{itemdecl}
const_buffer(const mutable_buffer& b);
\end{itemdecl}
\begin{itemdescr}
\pnum
\postconditions \tcode{data_ == b.data()} and \tcode{size_ == b.size()}.
\end{itemdescr}
\indexlibrarymember{data}{const_buffer}%
\begin{itemdecl}
const void* data() const noexcept;
\end{itemdecl}
\begin{itemdescr}
\pnum
\returns \tcode{data_}.
\end{itemdescr}
\indexlibrarymember{size}{const_buffer}%
\begin{itemdecl}
size_t size() const noexcept;
\end{itemdecl}
\begin{itemdescr}
\pnum
\returns \tcode{size_}.
\end{itemdescr}
\indexlibrarymember{operator+=}{const_buffer}%
\begin{itemdecl}
const_buffer& operator+=(size_t n) noexcept;
\end{itemdecl}
\begin{itemdescr}
\pnum
\effects Sets \tcode{data_} to \tcode{static_cast<const char*>(data_) + min(n, size_)}, and then \tcode{size_} to \tcode{size_ - min(n, size_)}.
\pnum
\returns \tcode{*this}.
\end{itemdescr}
\rSec1[buffer.traits]{Buffer type traits}
\indexlibrary{\idxcode{is_mutable_buffer_sequence}}%
\indexlibrary{\idxcode{is_const_buffer_sequence}}%
\indexlibrary{\idxcode{is_dynamic_buffer}}%
\begin{codeblock}
namespace std {
namespace experimental {
namespace net {
inline namespace v1 {
template<class T> struct is_mutable_buffer_sequence;
template<class T> struct is_const_buffer_sequence;
template<class T> struct is_dynamic_buffer;
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
\end{codeblock}
\pnum
This subclause contains templates that may be used to query the properties of a type at compile time. Each of these templates is a UnaryTypeTrait (\CppXref{meta.rqmts}) with a BaseCharacteristic of \tcode{true_type} if the corresponding condition is true, otherwise \tcode{false_type}.
\begin{libreqtab3}
{Buffer type traits}
{tab:buffer.traits.requirements}
\\ \topline
\lhdr{Template} &
\chdr{Condition} &
\rhdr{Preconditions} \\ \capsep
\endfirsthead
\continuedcaption\\
\hline
\lhdr{Template} &
\chdr{Condition} &
\rhdr{Preconditions} \\ \capsep
\endhead
\tcode{template<class T>}\br
\tcode{struct is_mutable_buffer_sequence} &
\tcode{T} meets the syntactic requirements for mutable buffer sequence~(\ref{buffer.reqmts.mutablebuffersequence}). &
\tcode{T} is a complete type. \\ \rowsep
\tcode{template<class T>}\br
\tcode{struct is_const_buffer_sequence} &
\tcode{T} meets the syntactic requirements for constant buffer sequence~(\ref{buffer.reqmts.constbuffersequence}). &
\tcode{T} is a complete type. \\ \rowsep
\tcode{template<class T>}\br
\tcode{struct is_dynamic_buffer} &
\tcode{T} meets the syntactic requirements for dynamic buffer~(\ref{buffer.reqmts.dynamicbuffer}). &
\tcode{T} is a complete type. \\
\end{libreqtab3}
\rSec1[buffer.seq.access]{Buffer sequence access}
\indexlibrary{\idxcode{buffer_sequence_begin}}%
\begin{itemdecl}
const mutable_buffer* buffer_sequence_begin(const mutable_buffer& b) noexcept;
const const_buffer* buffer_sequence_begin(const const_buffer& b) noexcept;
\end{itemdecl}
\begin{itemdescr}
\pnum
\returns \tcode{std::addressof(b)}.
\end{itemdescr}
\indexlibrary{\idxcode{buffer_sequence_end}}%
\begin{itemdecl}
const mutable_buffer* buffer_sequence_end(const mutable_buffer& b) noexcept;
const const_buffer* buffer_sequence_end(const const_buffer& b) noexcept;
\end{itemdecl}
\begin{itemdescr}
\pnum
\returns \tcode{std::addressof(b) + 1}.
\end{itemdescr}
\indexlibrary{\idxcode{buffer_sequence_begin}}%
\begin{itemdecl}
template<class C> auto buffer_sequence_begin(C& c) noexcept -> decltype(c.begin());
template<class C> auto buffer_sequence_begin(const C& c) noexcept -> decltype(c.begin());
\end{itemdecl}
\begin{itemdescr}
\pnum
\returns \tcode{c.begin()}.
\end{itemdescr}
\indexlibrary{\idxcode{buffer_sequence_end}}%
\begin{itemdecl}
template<class C> auto buffer_sequence_end(C& c) noexcept -> decltype(c.end());
template<class C> auto buffer_sequence_end(const C& c) noexcept -> decltype(c.end());
\end{itemdecl}
\begin{itemdescr}
\pnum
\returns \tcode{c.end()}.
\end{itemdescr}
\rSec1[buffer.size]{Function \tcode{buffer_size}}
\indexlibrary{\idxcode{buffer_sequence_size}}%
\begin{itemdecl}
template<class ConstBufferSequence>
size_t buffer_size(const ConstBufferSequence& buffers) noexcept;
\end{itemdecl}
\begin{itemdescr}
\pnum
\returns The total size of all buffers in the sequence, as if computed as follows:
\begin{codeblock}
size_t total_size = 0;
auto i = std::experimental::net::buffer_sequence_begin(buffers);
auto end = std::experimental::net::buffer_sequence_end(buffers);
for (; i != end; ++i)
{
const_buffer b(*i);
total_size += b.size();
}
return total_size;
\end{codeblock}
\end{itemdescr}
\rSec1[buffer.copy]{Function \tcode{buffer_copy}}
\indexlibrary{\idxcode{buffer_copy}}%
\begin{itemdecl}
template<class MutableBufferSequence, class ConstBufferSequence>
size_t buffer_copy(const MutableBufferSequence& dest,
const ConstBufferSequence& source) noexcept;
template<class MutableBufferSequence, class ConstBufferSequence>
size_t buffer_copy(const MutableBufferSequence& dest,
const ConstBufferSequence& source,
size_t max_size) noexcept;
\end{itemdecl}
\begin{itemdescr}
\pnum
\effects Copies bytes from the buffer sequence \tcode{source} to the buffer sequence \tcode{dest}, as if by calls to \tcode{memcpy}.
\pnum
The number of bytes copied is the lesser of:
\begin{itemize}
\item
\tcode{buffer_size(dest)};
\item
\tcode{buffer_size(source)}; and
\item
\tcode{max_size}, if specified.
\end{itemize}
\pnum
The mutable buffer sequence \tcode{dest} specifies memory where the data should be placed. The operation always fills a buffer in the sequence completely before proceeding to the next.
\pnum
The constant buffer sequence \tcode{source} specifies memory where the data to be written is located. The operation always copies a buffer in the sequence completely before proceeding to the next.
\pnum
\returns The number of bytes copied from \tcode{source} to \tcode{dest}.
\end{itemdescr}
\rSec1[buffer.arithmetic]{Buffer arithmetic}
\begin{itemdecl}
mutable_buffer operator+(const mutable_buffer& b, size_t n) noexcept;
mutable_buffer operator+(size_t n, const mutable_buffer& b) noexcept;
\end{itemdecl}
\begin{itemdescr}
\pnum
\returns A \tcode{mutable_buffer} equivalent to
\begin{codeblock}
mutable_buffer(
static_cast<char*>(b.data()) + min(n, b.size()),
b.size() - min(n, b.size()));
\end{codeblock}
\end{itemdescr}
\begin{itemdecl}
const_buffer operator+(const const_buffer& b, size_t n) noexcept;
const_buffer operator+(size_t n, const const_buffer& b) noexcept;
\end{itemdecl}
\begin{itemdescr}
\pnum
\returns A \tcode{const_buffer} equivalent to
\begin{codeblock}
const_buffer(
static_cast<const char*>(b.data()) + min(n, b.size()),
b.size() - min(n, b.size()));
\end{codeblock}
\end{itemdescr}
\rSec1[buffer.creation]{Buffer creation functions}
\pnum
In the functions below, \tcode{T} shall be a trivially copyable or standard-layout type (\CppXref{basic.types}).
\pnum
For the function overloads below that accept an argument of type \tcode{vector<>}, the buffer objects returned are invalidated by any vector operation that also invalidates all references, pointers and iterators referring to the elements in the sequence (\CppXref{vector}).
\pnum
For the function overloads below that accept an argument of type \tcode{basic_string<>}, the buffer objects returned are invalidated according to the rules defined for invalidation of references, pointers and iterators referring to elements of the sequence (\CppXref{string.require}).
\indexlibrary{\idxcode{buffer}}%
\begin{itemdecl}