Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

  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
// <experimental/buffer> -*- C++ -*-

// Copyright (C) 2015-2020 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  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 3, 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.

// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.

// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
// <http://www.gnu.org/licenses/>.

/** @file experimental/buffer
 *  This is a TS C++ Library header.
 *  @ingroup networking-ts
 */

#ifndef _GLIBCXX_EXPERIMENTAL_BUFFER
#define _GLIBCXX_EXPERIMENTAL_BUFFER 1

#pragma GCC system_header

#if __cplusplus >= 201402L

#include <array>
#include <string>
#include <system_error>
#include <vector>
#include <cstring>
#include <experimental/string_view>
#include <experimental/bits/net.h>

namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
namespace experimental
{
namespace net
{
inline namespace v1
{

  /** @addtogroup networking-ts
   *  @{
   */

  enum class stream_errc {    // TODO decide values
    eof = 1,
    not_found = 2
  };

  const error_category& stream_category() noexcept // TODO not inline
  {
    struct __cat : error_category
    {
      const char* name() const noexcept { return "stream"; }

      std::string message(int __e) const
      {
	if (__e == (int)stream_errc::eof)
	  return "EOF";
	else if (__e == (int)stream_errc::not_found)
	  return "not found";
	return "stream";
      }

      virtual void __message(int) { } // TODO dual ABI XXX
    };
    static __cat __c;
    return __c;
  }

  inline error_code
  make_error_code(stream_errc __e) noexcept
  { return error_code(static_cast<int>(__e), stream_category()); }

  inline error_condition
  make_error_condition(stream_errc __e) noexcept
  { return error_condition(static_cast<int>(__e), stream_category()); }

  class mutable_buffer
  {
  public:
    // constructors:
    mutable_buffer() noexcept : _M_data(), _M_size() { }

    mutable_buffer(void* __p, size_t __n) noexcept
    : _M_data(__p), _M_size(__n) { }

    // members:
    void* data() const noexcept { return _M_data; }
    size_t size() const noexcept { return _M_size; }

  private:
    void*	_M_data;
    size_t	_M_size;
  };

  class const_buffer
  {
  public:
    // constructors:
    const_buffer() noexcept : _M_data(), _M_size() { }

    const_buffer(const void* __p, size_t __n) noexcept
    : _M_data(__p), _M_size(__n) { }

    const_buffer(const mutable_buffer& __b) noexcept
    : _M_data(__b.data()), _M_size(__b.size()) { }

    // members:
    const void* data() const noexcept { return _M_data; }
    size_t size() const noexcept { return _M_size; }

  private:
    const void*	_M_data;
    size_t	_M_size;
  };


  /** @brief buffer sequence access
   *
   * Uniform access to types that meet the BufferSequence requirements.
   * @{
   */

  inline const mutable_buffer*
  buffer_sequence_begin(const mutable_buffer& __b)
  { return std::addressof(__b); }

  inline const const_buffer*
  buffer_sequence_begin(const const_buffer& __b)
  { return std::addressof(__b); }

  inline const mutable_buffer*
  buffer_sequence_end(const mutable_buffer& __b)
  { return std::addressof(__b) + 1; }

  inline const const_buffer*
  buffer_sequence_end(const const_buffer& __b)
  { return std::addressof(__b) + 1; }

  template<typename _Cont>
    auto
    buffer_sequence_begin(_Cont& __c) -> decltype(__c.begin())
    { return __c.begin(); }

  template<typename _Cont>
    auto
    buffer_sequence_begin(const _Cont& __c) -> decltype(__c.begin())
    { return __c.begin(); }

  template<typename _Cont>
    auto
    buffer_sequence_end(_Cont& __c) -> decltype(__c.end())
    { return __c.end(); }

  template<typename _Cont>
    auto
    buffer_sequence_end(const _Cont& __c) -> decltype(__c.end())
    { return __c.end(); }

  /// @}


  /** @brief buffer type traits
   *
   * @{
   */

  template<typename _Tp, typename _Buffer,
	   typename _Begin
	    = decltype(net::buffer_sequence_begin(std::declval<_Tp&>())),
	   typename _End
	    = decltype(net::buffer_sequence_end(std::declval<_Tp&>()))>
    using __buffer_sequence = enable_if_t<__and_<
      __is_value_constructible<_Tp>, is_same<_Begin, _End>,
      is_convertible<typename iterator_traits<_Begin>::value_type, _Buffer>
      >::value>;

  template<typename _Tp, typename _Buffer, typename = void>
    struct __is_buffer_sequence : false_type
    { };

  template<typename _Tp, typename _Buffer>
    struct __is_buffer_sequence<_Tp, _Buffer, __buffer_sequence<_Tp, _Buffer>>
    : true_type
    { };

  template<typename _Tp>
    struct is_mutable_buffer_sequence
    : __is_buffer_sequence<_Tp, mutable_buffer>::type
    { };

  template<typename _Tp>
    struct is_const_buffer_sequence
    : __is_buffer_sequence<_Tp, const_buffer>::type
    { };

  template<typename _Tp>
    constexpr bool is_mutable_buffer_sequence_v
      = is_mutable_buffer_sequence<_Tp>::value;

  template<typename _Tp>
    constexpr bool is_const_buffer_sequence_v
      = is_const_buffer_sequence<_Tp>::value;

  template<typename _Tp, typename = void>
    struct __is_dynamic_buffer_impl : false_type
    { };

  // Check DynamicBuffer requirements.
  template<typename _Tp, typename _Up = remove_const_t<_Tp>>
    auto
    __dynamic_buffer_reqs(_Up* __x = 0, const _Up* __x1 = 0, size_t __n = 0)
    -> enable_if_t<__and_<
      is_move_constructible<_Up>,
      is_const_buffer_sequence<typename _Tp::const_buffers_type>,
      is_mutable_buffer_sequence<typename _Tp::mutable_buffers_type>,
      is_same<decltype(__x1->size()), size_t>,
      is_same<decltype(__x1->max_size()), size_t>,
      is_same<decltype(__x1->capacity()), size_t>,
      is_same<decltype(__x1->data()), typename _Tp::const_buffers_type>,
      is_same<decltype(__x->prepare(__n)), typename _Tp::mutable_buffers_type>,
      is_void<decltype(__x->commit(__n), __x->consume(__n), void())>
    >::value>;

  template<typename _Tp>
    struct __is_dynamic_buffer_impl<_Tp,
				    decltype(__dynamic_buffer_reqs<_Tp>())>
    : true_type
    { };

  template<typename _Tp>
    struct is_dynamic_buffer : __is_dynamic_buffer_impl<_Tp>::type
    { };

  template<typename _Tp>
    constexpr bool is_dynamic_buffer_v = is_dynamic_buffer<_Tp>::value;

  /// @}

  /// buffer size
  template<typename _ConstBufferSequence>
    size_t
    buffer_size(const _ConstBufferSequence& __buffers) noexcept
    {
      size_t __total_size = 0;
      auto __i = net::buffer_sequence_begin(__buffers);
      const auto __end = net::buffer_sequence_end(__buffers);
      for (; __i != __end; ++__i)
	__total_size += const_buffer(*__i).size();
      return __total_size;
    }

  template<typename _ConstBufferSequence>
    bool
    __buffer_empty(const _ConstBufferSequence& __buffers) noexcept
    {
      auto __i = net::buffer_sequence_begin(__buffers);
      const auto __end = net::buffer_sequence_end(__buffers);
      for (; __i != __end; ++__i)
	if (const_buffer(*__i).size() != 0)
	  return false;
      return true;
    }

  // buffer copy:

  template<typename _MutableBufferSequence, typename _ConstBufferSequence>
    size_t
    buffer_copy(const _MutableBufferSequence& __dest,
		const _ConstBufferSequence& __source,
		size_t __max_size) noexcept
    {
      size_t __total_size = 0;
      auto __to_i = net::buffer_sequence_begin(__dest);
      const auto __to_end = net::buffer_sequence_end(__dest);
      auto __from_i = net::buffer_sequence_begin(__source);
      const auto __from_end = net::buffer_sequence_end(__source);
      mutable_buffer __to;
      const_buffer __from;
      while (((__from_i != __from_end && __to_i != __to_end)
	    || (__from.size() && __to.size()))
	  && __total_size < __max_size)
	{
	  if (__from.size() == 0)
	    __from = const_buffer{*__from_i++};
	  if (__to.size() == 0)
	    __to = mutable_buffer{*__to_i++};

	  size_t __n = std::min(__from.size(), __to.size());
	  __n = std::min(__n, __max_size - __total_size);
	  std::memcpy(__to.data(), __from.data(), __n);
	  __from = { (const char*)__from.data() + __n, __from.size() - __n };
	  __to = { (char*)__to.data() + __n, __to.size() - __n };
	  __total_size += __n;
	}
      return __total_size;
    }

  template<typename _MutableBufferSequence, typename _ConstBufferSequence>
    inline size_t
    buffer_copy(const _MutableBufferSequence& __dest,
		const _ConstBufferSequence& __source) noexcept
    { return net::buffer_copy(__dest, __source, size_t{-1}); }


  // buffer arithmetic:

  inline mutable_buffer
  operator+(const mutable_buffer& __b, size_t __n) noexcept
  {
    if (__n > __b.size())
      __n = __b.size();
    return { static_cast<char*>(__b.data()) + __n, __b.size() - __n };
  }

  inline mutable_buffer
  operator+(size_t __n, const mutable_buffer& __b) noexcept
  { return __b + __n; }

  inline const_buffer
  operator+(const const_buffer& __b, size_t __n) noexcept
  {
    if (__n > __b.size())
      __n = __b.size();
    return { static_cast<const char*>(__b.data()) + __n, __b.size() - __n };
  }

  inline const_buffer
  operator+(size_t __n, const const_buffer& __b) noexcept
  { return __b + __n; }

  // buffer creation:

  inline mutable_buffer
  buffer(void* __p, size_t __n) noexcept
  { return { __p, __n }; }

  inline const_buffer
  buffer(const void* __p, size_t __n) noexcept
  { return { __p, __n }; }

  inline mutable_buffer
  buffer(const mutable_buffer& __b) noexcept
  { return __b; }

  inline mutable_buffer
  buffer(const mutable_buffer& __b, size_t __n) noexcept
  { return { __b.data(), std::min(__b.size(), __n) }; }

  inline const_buffer
  buffer(const const_buffer& __b) noexcept
  { return __b; }

  inline const_buffer
  buffer(const const_buffer& __b, size_t __n) noexcept
  { return { __b.data(), std::min(__b.size(), __n) }; }

  template<typename _Tp>
    inline mutable_buffer
    __to_mbuf(_Tp* __data, size_t __n)
    { return { __n ? __data : nullptr, __n * sizeof(_Tp) }; }

  template<typename _Tp>
    inline const_buffer
    __to_cbuf(const _Tp* __data, size_t __n)
    { return { __n ? __data : nullptr, __n * sizeof(_Tp) }; }

  template<typename _Tp, size_t _Nm>
    inline mutable_buffer
    buffer(_Tp (&__data)[_Nm]) noexcept
    { return net::__to_mbuf(__data, _Nm); }

  template<typename _Tp, size_t _Nm>
    inline const_buffer
    buffer(const _Tp (&__data)[_Nm]) noexcept
    { return net::__to_cbuf(__data, _Nm); }

  template<typename _Tp, size_t _Nm>
    inline mutable_buffer
    buffer(array<_Tp, _Nm>& __data) noexcept
    { return net::__to_mbuf(__data.data(), _Nm); }

  template<typename _Tp, size_t _Nm>
    inline const_buffer
    buffer(array<const _Tp, _Nm>& __data) noexcept
    { return net::__to_cbuf(__data.data(), __data.size()); }

  template<typename _Tp, size_t _Nm>
    inline const_buffer
    buffer(const array<_Tp, _Nm>& __data) noexcept
    { return net::__to_cbuf(__data.data(), __data.size()); }

  template<typename _Tp, typename _Allocator>
    inline mutable_buffer
    buffer(vector<_Tp, _Allocator>& __data) noexcept
    { return net::__to_mbuf(__data.data(), __data.size()); }

  template<typename _Tp, typename _Allocator>
    inline const_buffer
    buffer(const vector<_Tp, _Allocator>& __data) noexcept
    { return net::__to_cbuf(__data.data(), __data.size()); }

  template<typename _CharT, typename _Traits, typename _Allocator>
    inline mutable_buffer
    buffer(basic_string<_CharT, _Traits, _Allocator>& __data) noexcept
    { return net::__to_mbuf(&__data.front(), __data.size()); }

  template<typename _CharT, typename _Traits, typename _Allocator>
    inline const_buffer
    buffer(const basic_string<_CharT, _Traits, _Allocator>& __data) noexcept
    { return net::__to_cbuf(&__data.front(), __data.size()); }

  template<typename _CharT, typename _Traits>
    inline const_buffer
    buffer(basic_string_view<_CharT, _Traits> __data) noexcept
    { return net::__to_cbuf(__data.data(), __data.size()); }

  template<typename _Tp, size_t _Nm>
    inline mutable_buffer
    buffer(_Tp (&__data)[_Nm], size_t __n) noexcept
    { return buffer(net::buffer(__data), __n * sizeof(_Tp)); }

  template<typename _Tp, size_t _Nm>
    inline const_buffer
    buffer(const _Tp (&__data)[_Nm], size_t __n) noexcept
    { return buffer(net::buffer(__data), __n * sizeof(_Tp)); }

  template<typename _Tp, size_t _Nm>
    inline mutable_buffer
    buffer(array<_Tp, _Nm>& __data, size_t __n) noexcept
    { return buffer(net::buffer(__data), __n * sizeof(_Tp)); }

  template<typename _Tp, size_t _Nm>
    inline const_buffer
    buffer(array<const _Tp, _Nm>& __data, size_t __n) noexcept
    { return buffer(net::buffer(__data), __n * sizeof(_Tp)); }

  template<typename _Tp, size_t _Nm>
    inline const_buffer
    buffer(const array<_Tp, _Nm>& __data, size_t __n) noexcept
    { return buffer(net::buffer(__data), __n * sizeof(_Tp)); }

  template<typename _Tp, typename _Allocator>
    inline mutable_buffer
    buffer(vector<_Tp, _Allocator>& __data, size_t __n) noexcept
    { return buffer(net::buffer(__data), __n * sizeof(_Tp)); }

  template<typename _Tp, typename _Allocator>
    inline const_buffer
    buffer(const vector<_Tp, _Allocator>& __data, size_t __n) noexcept
    { return buffer(net::buffer(__data), __n * sizeof(_Tp)); }

  template<typename _CharT, typename _Traits, typename _Allocator>
    inline mutable_buffer
    buffer(basic_string<_CharT, _Traits, _Allocator>& __data,
	   size_t __n) noexcept
    { return buffer(net::buffer(__data), __n * sizeof(_CharT)); }

  template<typename _CharT, typename _Traits, typename _Allocator>
    inline const_buffer
    buffer(const basic_string<_CharT, _Traits, _Allocator>& __data,
	   size_t __n) noexcept
    { return buffer(net::buffer(__data), __n * sizeof(_CharT)); }

  template<typename _CharT, typename _Traits>
    inline const_buffer
    buffer(basic_string_view<_CharT, _Traits> __data, size_t __n) noexcept
    { return buffer(net::buffer(__data), __n * sizeof(_CharT)); }


  template<typename _Sequence>
    class __dynamic_buffer_base
    {
    public:
      // types:
      typedef const_buffer const_buffers_type;
      typedef mutable_buffer mutable_buffers_type;

      // constructors:
      explicit
      __dynamic_buffer_base(_Sequence& __seq) noexcept
      : _M_seq(__seq), _M_size(__seq.size()), _M_max_size(__seq.max_size())
      { }

      __dynamic_buffer_base(_Sequence& __seq, size_t __maximum_size) noexcept
      : _M_seq(__seq), _M_size(__seq.size()), _M_max_size(__maximum_size)
      { __glibcxx_assert(__seq.size() <= __maximum_size); }

      __dynamic_buffer_base(__dynamic_buffer_base&&) = default;

      // members:
      size_t size() const noexcept { return _M_size; }
      size_t max_size() const noexcept { return _M_max_size; }
      size_t capacity() const noexcept { return _M_seq.capacity(); }

      const_buffers_type
      data() const noexcept
      { return net::buffer(_M_seq, _M_size); }

      mutable_buffers_type
      prepare(size_t __n)
      {
	if ((_M_size + __n) > _M_max_size)
	  __throw_length_error("dynamic_vector_buffer::prepare");

	_M_seq.resize(_M_size + __n);
	return buffer(net::buffer(_M_seq) + _M_size, __n);
      }

      void
      commit(size_t __n)
      {
	_M_size += std::min(__n, _M_seq.size() - _M_size);
	_M_seq.resize(_M_size);
      }

      void
      consume(size_t __n)
      {
	size_t __m = std::min(__n, _M_size);
	_M_seq.erase(_M_seq.begin(), _M_seq.begin() + __m);
	_M_size -= __m;
      }

    private:
      _Sequence&	_M_seq;
      size_t		_M_size;
      const size_t	_M_max_size;
    };

  template<typename _Tp, typename _Allocator>
    class dynamic_vector_buffer
    : public __dynamic_buffer_base<vector<_Tp, _Allocator>>
    {
    public:
      using __dynamic_buffer_base<vector<_Tp, _Allocator>>::__dynamic_buffer_base;
    };

  template<typename _CharT, typename _Traits, typename _Allocator>
    class dynamic_string_buffer
    : public __dynamic_buffer_base<basic_string<_CharT, _Traits, _Allocator>>
    {
    public:
      using __dynamic_buffer_base<basic_string<_CharT, _Traits, _Allocator>>::
	__dynamic_buffer_base;
    };

  // dynamic buffer creation:

  template<typename _Tp, typename _Allocator>
    inline dynamic_vector_buffer<_Tp, _Allocator>
    dynamic_buffer(vector<_Tp, _Allocator>& __vec) noexcept
    { return dynamic_vector_buffer<_Tp, _Allocator>{__vec}; }

  template<typename _Tp, typename _Allocator>
    inline dynamic_vector_buffer<_Tp, _Allocator>
    dynamic_buffer(vector<_Tp, _Allocator>& __vec, size_t __n) noexcept
    { return {__vec, __n}; }

  template<typename _CharT, typename _Traits, typename _Allocator>
    inline dynamic_string_buffer<_CharT, _Traits, _Allocator>
    dynamic_buffer(basic_string<_CharT, _Traits, _Allocator>& __str) noexcept
    { return dynamic_string_buffer<_CharT, _Traits, _Allocator>{__str}; }

  template<typename _CharT, typename _Traits, typename _Allocator>
    inline dynamic_string_buffer<_CharT, _Traits, _Allocator>
    dynamic_buffer(basic_string<_CharT, _Traits, _Allocator>& __str,
		   size_t __n) noexcept
    { return {__str, __n}; }

  class transfer_all
  {
  public:
    size_t operator()(const error_code& __ec, size_t) const
    { return !__ec ? 1500 : 0; }
  };

  class transfer_at_least
  {
  public:
    explicit transfer_at_least(size_t __m) : _M_minimum(__m) { }

    size_t operator()(const error_code& __ec, size_t __n) const
    { return !__ec  && __n < _M_minimum ? _M_minimum - __n : 0; }

  private:
    size_t _M_minimum;
  };

  class transfer_exactly
  {
  public:
    explicit transfer_exactly(size_t __e) : _M_exact(__e) { }

    size_t operator()(const error_code& __ec, size_t __n) const
    {
      size_t _Nm = -1;
      return !__ec  && __n < _M_exact ? std::min(_M_exact - __n, _Nm) : 0;
    }

  private:
    size_t _M_exact;
  };

  /** @brief synchronous read operations
   * @{
   */

  template<typename _SyncReadStream, typename _MutableBufferSequence,
	   typename _CompletionCondition>
    enable_if_t<is_mutable_buffer_sequence<_MutableBufferSequence>::value,
		size_t>
    read(_SyncReadStream& __stream, const _MutableBufferSequence& __buffers,
	 _CompletionCondition __completion_condition, error_code& __ec)
    {
      __ec.clear();
      auto __i = net::buffer_sequence_begin(__buffers);
      auto __end = net::buffer_sequence_end(__buffers);
      mutable_buffer __to;
      size_t __total = 0;
      size_t __n;
      while ((__n = __completion_condition(__ec, __total))
	  && (__i != __end || __to.size()))
	{
	  if (__to.size() == 0)
	    __to = mutable_buffer(*__i++);
	  __n = __stream.read_some(buffer(__to, __n), __ec);
	  __to = __to + __n;
	  __total += __n;
	}
      return __total;
    }

  template<typename _SyncReadStream, typename _MutableBufferSequence>
    inline
    enable_if_t<is_mutable_buffer_sequence<_MutableBufferSequence>::value,
		size_t>
    read(_SyncReadStream& __stream, const _MutableBufferSequence& __buffers)
    {
      error_code __ec;
      return net::read(__stream, __buffers, transfer_all{}, __ec);
    }

  template<typename _SyncReadStream, typename _MutableBufferSequence>
    inline
    enable_if_t<is_mutable_buffer_sequence<_MutableBufferSequence>::value,
		size_t>
    read(_SyncReadStream& __stream, const _MutableBufferSequence& __buffers,
	 error_code& __ec)
    { return net::read(__stream, __buffers, transfer_all{}, __ec); }

  template<typename _SyncReadStream, typename _MutableBufferSequence,
	   typename _CompletionCondition>
    inline
    enable_if_t<is_mutable_buffer_sequence<_MutableBufferSequence>::value,
		size_t>
    read(_SyncReadStream& __stream, const _MutableBufferSequence& __buffers,
	 _CompletionCondition __completion_condition)
    {
      error_code __ec;
      return net::read(__stream, __buffers, __completion_condition, __ec);
    }


  template<typename _SyncReadStream, typename _DynamicBuffer,
	   typename _CompletionCondition>
    enable_if_t<is_dynamic_buffer<decay_t<_DynamicBuffer>>::value, size_t>
    read(_SyncReadStream& __stream, _DynamicBuffer&& __b,
	 _CompletionCondition __completion_condition, error_code& __ec)
    {
      const size_t __limit = 64;
      __ec.clear();
      size_t __cap = std::max(__b.capacity() - __b.size(), __limit);
      size_t __total = 0;
      size_t __n;
      while ((__n = __completion_condition(__ec, __total))
	  && __b.size() != __b.max_size())
	{
	  __n =  std::min(__n, __b.max_size() - __b.size());
	  size_t __cap = std::max(__b.capacity() - __b.size(), __limit);
	  mutable_buffer __to = __b.prepare(std::min(__cap, __n));
	  __n = __stream.read_some(__to, __ec);
	  __to = __to + __n;
	  __total += __n;
	  __b.commit(__n);
	}
      return __total;
    }

  template<typename _SyncReadStream, typename _DynamicBuffer>
    inline enable_if_t<is_dynamic_buffer<_DynamicBuffer>::value, size_t>
    read(_SyncReadStream& __stream, _DynamicBuffer&& __b)
    {
      error_code __ec;
      return net::read(__stream, __b, transfer_all{}, __ec);
    }

  template<typename _SyncReadStream, typename _DynamicBuffer>
    inline enable_if_t<is_dynamic_buffer<_DynamicBuffer>::value, size_t>
    read(_SyncReadStream& __stream, _DynamicBuffer&& __b, error_code& __ec)
    {
      return net::read(__stream, __b, transfer_all{}, __ec);
    }

  template<typename _SyncReadStream, typename _DynamicBuffer,
	   typename _CompletionCondition>
    inline enable_if_t<is_dynamic_buffer<_DynamicBuffer>::value, size_t>
    read(_SyncReadStream& __stream, _DynamicBuffer&& __b,
	 _CompletionCondition __completion_condition)
    {
      error_code __ec;
      return net::read(__stream, __b, __completion_condition, __ec);
    }

  /// @}

  /** @brief asynchronous read operations
   * @{
   */

  template<typename _AsyncReadStream, typename _MutableBufferSequence,
	   typename _CompletionCondition, typename _CompletionToken>
    __deduced_t<_CompletionToken, void(error_code, size_t)>
    async_read(_AsyncReadStream& __stream,
	       const _MutableBufferSequence& __buffers,
	       _CompletionCondition __completion_condition,
	       _CompletionToken&& __token)
    {
      error_code __ec;
    }

  template<typename _AsyncReadStream, typename _MutableBufferSequence,
	   typename _CompletionToken>
    inline __deduced_t<_CompletionToken, void(error_code, size_t)>
    async_read(_AsyncReadStream& __stream,
	       const _MutableBufferSequence& __buffers,
	       _CompletionToken&& __token)
    {
      return net::async_read(__stream, __buffers, transfer_all{},
			     std::forward<_CompletionToken>(__token));
    }

  template<typename _AsyncReadStream, typename _DynamicBuffer,
	   typename _CompletionCondition, typename _CompletionToken>
    __deduced_t<_CompletionToken, void(error_code, size_t)>
    async_read(_AsyncReadStream& __stream, _DynamicBuffer&& __b,
	       _CompletionCondition __completion_condition,
	       _CompletionToken&& __token)
    {
      error_code __ec;
    }

  template<typename _AsyncReadStream, typename _DynamicBuffer,
	   typename _CompletionToken>
    inline __deduced_t<_CompletionToken, void(error_code, size_t)>
    async_read(_AsyncReadStream& __stream, _DynamicBuffer&& __b,
	       _CompletionToken&& __token)
    {
      return net::async_read(__stream, __b, transfer_all{},
			     std::forward<_CompletionToken>(__token));
    }

  /// @}

#if 0
  /** @brief synchronous write operations:
   * @{
   */

  template<typename _SyncWriteStream, typename _ConstBufferSequence>
    size_t write(_SyncWriteStream& __stream,
                 const _ConstBufferSequence& __buffers);
  template<typename _SyncWriteStream, typename _ConstBufferSequence>
    size_t write(_SyncWriteStream& __stream,
                 const _ConstBufferSequence& __buffers, error_code& __ec);
  template<typename _SyncWriteStream, typename _ConstBufferSequence,
    typename _CompletionCondition>
      size_t write(_SyncWriteStream& __stream,
                   const _ConstBufferSequence& __buffers,
                   _CompletionCondition __completion_condition);
  template<typename _SyncWriteStream, typename _ConstBufferSequence,
    typename _CompletionCondition>
      size_t write(_SyncWriteStream& __stream,
                   const _ConstBufferSequence& __buffers,
                   _CompletionCondition __completion_condition,
                   error_code& __ec);

  template<typename _SyncWriteStream, typename _DynamicBuffer>
    size_t write(_SyncWriteStream& __stream, _DynamicBuffer&& __b);
  template<typename _SyncWriteStream, typename _DynamicBuffer>
    size_t write(_SyncWriteStream& __stream, _DynamicBuffer&& __b, error_code& __ec);
  template<typename _SyncWriteStream, typename _DynamicBuffer, typename _CompletionCondition>
    size_t write(_SyncWriteStream& __stream, _DynamicBuffer&& __b,
                 _CompletionCondition __completion_condition);
  template<typename _SyncWriteStream, typename _DynamicBuffer, typename _CompletionCondition>
    size_t write(_SyncWriteStream& __stream, _DynamicBuffer&& __b,
                 _CompletionCondition __completion_condition, error_code& __ec);

  /// @}

  /** @brief asynchronous write operations
   * @{
   */

  template<typename _AsyncWriteStream, typename _ConstBufferSequence,
    typename _CompletionToken>
      DEDUCED async_write(_AsyncWriteStream& __stream,
                       const _ConstBufferSequence& __buffers,
                       _CompletionToken&& __token);
  template<typename _AsyncWriteStream, typename _ConstBufferSequence,
    typename _CompletionCondition, typename _CompletionToken>
      DEDUCED async_write(_AsyncWriteStream& __stream,
                       const _ConstBufferSequence& __buffers,
                       _CompletionCondition __completion_condition,
                       _CompletionToken&& __token);

  template<typename _AsyncWriteStream, typename _DynamicBuffer, typename _CompletionToken>
    DEDUCED async_write(_AsyncWriteStream& __stream,
                     _DynamicBuffer&& __b, _CompletionToken&& __token);
  template<typename _AsyncWriteStream, typename _DynamicBuffer,
    typename _CompletionCondition, typename _CompletionToken>
      DEDUCED async_write(_AsyncWriteStream& __stream,
                       _DynamicBuffer&& __b,
                       _CompletionCondition __completion_condition,
                       _CompletionToken&& __token);

  /// @}

  /** @brief synchronous delimited read operations
   * @{
   */

  template<typename _SyncReadStream, typename _DynamicBuffer>
    size_t read_until(_SyncReadStream& __s, _DynamicBuffer&& __b, char __delim);
  template<typename _SyncReadStream, typename _DynamicBuffer>
    size_t read_until(_SyncReadStream& __s, _DynamicBuffer&& __b,
                      char __delim, error_code& __ec);
  template<typename _SyncReadStream, typename _DynamicBuffer>
    size_t read_until(_SyncReadStream& __s, _DynamicBuffer&& __b, string_view __delim);
  template<typename _SyncReadStream, typename _DynamicBuffer>
    size_t read_until(_SyncReadStream& __s, _DynamicBuffer&& __b,
                      string_view __delim, error_code& __ec);

  /// @}

  /** @brief asynchronous delimited read operations
   * @{
   */

  template<typename _AsyncReadStream, typename _DynamicBuffer, typename _CompletionToken>
    DEDUCED async_read_until(_AsyncReadStream& __s,
                          _DynamicBuffer&& __b, char __delim,
                          _CompletionToken&& __token);
  template<typename _AsyncReadStream, typename _DynamicBuffer, typename _CompletionToken>
    DEDUCED async_read_until(_AsyncReadStream& __s,
                          _DynamicBuffer&& __b, string_view __delim,
                          _CompletionToken&& __token);

  /// @}

#endif
  /// @}

} // namespace v1
} // namespace net
} // namespace experimental

  template<>
    struct is_error_code_enum<experimental::net::v1::stream_errc>
    : public true_type {};

_GLIBCXX_END_NAMESPACE_VERSION
} // namespace std

#endif // C++14

#endif // _GLIBCXX_EXPERIMENTAL_BUFFER