Example #1
0
void
write_buffer(DynamicBuffer& b, string_view s)
{
    b.commit(boost::asio::buffer_copy(
        b.prepare(s.size()), boost::asio::buffer(
            s.data(), s.size())));
}
Example #2
0
 void
 body(DynamicBuffer& db)
 {
     if(! rand(4))
     {
         write(db, "Content-Length: 0\r\n\r\n");
         return;
     }
     if(rand(2))
     {
         auto const len = rand(500);
         write(db, "Content-Length: ", len, "\r\n\r\n");
         for(auto const& b : db.prepare(len))
         {
             auto p = boost::asio::buffer_cast<char*>(b);
             auto n = boost::asio::buffer_size(b);
             while(n--)
                 *p++ = static_cast<char>(32 + rand(26+26+10+6));
         }
         db.commit(len);
     }
     else
     {
         auto len = rand(500);
         write(db, "Transfer-Encoding: chunked\r\n\r\n");
         while(len > 0)
         {
             auto n = (std::min)(1 + rand(300), len);
             len -= n;
             write(db, to_hex(n), "\r\n");
             for(auto const& b : db.prepare(n))
             {
                 auto p = boost::asio::buffer_cast<char*>(b);
                 auto m = boost::asio::buffer_size(b);
                 while(m--)
                     *p++ = static_cast<char>(32 + rand(26+26+10+6));
             }
             db.commit(n);
             write(db, "\r\n");
         }
         write(db, "0\r\n\r\n");
     }
 }
Example #3
0
 size_type
 do_prepares(std::size_t repeat,
     std::size_t count, std::size_t size)
 {
     timer t;
     size_type total = 0;
     for(auto i = repeat; i--;)
     {
         DynamicBuffer b;
         for(auto j = count; j--;)
         {
             auto const n = fill(b.prepare(size));
             b.commit(n);
             total += n;
         }
     }
     return throughput(t.elapsed(), total);
 }
Example #4
0
void
write(DynamicBuffer& db, frame_header const& fh)
{
    using boost::asio::buffer;
    using boost::asio::buffer_copy;
    using namespace boost::endian;
    std::size_t n;
    std::uint8_t b[14];
    b[0] = (fh.fin ? 0x80 : 0x00) | static_cast<std::uint8_t>(fh.op);
    if(fh.rsv1)
        b[0] |= 0x40;
    if(fh.rsv2)
        b[0] |= 0x20;
    if(fh.rsv3)
        b[0] |= 0x10;
    b[1] = fh.mask ? 0x80 : 0x00;
    if(fh.len <= 125)
    {
        b[1] |= fh.len;
        n = 2;
    }
    else if(fh.len <= 65535)
    {
        b[1] |= 126;
        ::new(&b[2]) big_uint16_buf_t{
            (std::uint16_t)fh.len};
        n = 4;
    }
    else
    {
        b[1] |= 127;
        ::new(&b[2]) big_uint64_buf_t{fh.len};
        n = 10;
    }
    if(fh.mask)
    {
        native_to_little_uint32(fh.key, &b[n]);
        n += 4;
    }
    db.commit(buffer_copy(
        db.prepare(n), buffer(b)));
}
Example #5
0
 size_type
 do_hints(std::size_t repeat,
     std::size_t count, std::size_t size)
 {
     timer t;
     size_type total = 0;
     for(auto i = repeat; i--;)
     {
         DynamicBuffer b;
         for(auto j = count; j--;)
         {
             for(auto remain = size; remain;)
             {
                 auto const n = fill(b.prepare(
                     read_size(b, remain)));
                 b.commit(n);
                 remain -= n;
                 total += n;
             }
         }
     }
     return throughput(t.elapsed(), total);
 }