Title
[networking.ts] Relax pointer equivalence requirement for ConstBufferSequence
Status
new
Section
[buffer.reqmts.constbuffersequence]
Submitter
Vinnie Falco

Created on 2017-09-20.00:00:00 last changed 86 months ago

Messages

Date: 2017-10-08.13:50:52

Proposed resolution:

This wording is relative to N4588.

  1. Modify [buffer.reqmts.constbuffersequence] Table 13 "ConstBufferSequence requirements" as indicated:

    Table 13 — ConstBufferSequence requirements
    expression return type assertion/note
    pre/post-condition
    […]
    X u(x); post:
    equal(
      net::buffer_sequence_begin(x),
      net::buffer_sequence_end(x),
      net::buffer_sequence_begin(u),
      net::buffer_sequence_end(u),
      [](const typename X::value_type& v1,
         const typename X::value_type& v2)
        {
          const_buffer b1(v1);
          const_buffer b2(v2);
          return b1.data() == b2.data()
              && b1.size() == b2.size()
          return b1.size() == b2.size()
              && memcmp(b1.data(), b2.data(), b1.size()) == 0;
        })
    
Date: 2017-09-20.00:00:00

Addresses: networking.ts

The post-condition buffer sequence requirements mandate pointer equivalence. This means that a copies of buffer sequences must point to the same pieces of underlying memory. While this is appropriate for MutableBufferSequence, it is unnecessary for ConstBufferSequence and can actually prevent useful implementation strategies such as the following constant buffer sequence which avoids dynamic allocations:

/// A buffer sequence containing a chunk-encoding header
class chunk_size
{
public:
    // Storage for the longest hex string we might need
    class value_type
    {
        friend class chunk_size;

        // First byte holds the length
        char buf_[1 + 2 * sizeof(std::size_t)];

        template<class = void>
        void prepare(std::size_t n);

        template<class OutIter>
        static OutIter to_hex(OutIter last, std::size_t n)
        {
            if (n == 0)
            {
                *--last = '0';
                return last;
            }
            while (n)
            {
                *--last = "0123456789abcdef"[n & 0xf];
                n >>= 4;
            }
            return last;
        }
    public:
        operator boost::asio::const_buffer() const
        {
            return {
                buf_ + sizeof(buf_) - buf_[0],
                static_cast(buf_[0])
            };
        }
    };

    using const_iterator = value_type const*;

    chunk_size(chunk_size const& other) = default;

    /** Construct a chunk header

        @param n The number of octets in this chunk.
    */
    chunk_size(std::size_t n)
    {
        value_.prepare(n);
    }

    const_iterator begin() const
    {
        return &value_;
    }

    const_iterator end() const
    {
        return begin() + 1;
    }

private:
    value_type value_;
};
History
Date User Action Args
2017-10-08 13:50:52adminsetmessages: + msg9468
2017-09-20 00:00:00admincreate