28 const uint16_t RLPXFrameWriter::EmptyFrameLength =
h128::size * 3;
29 const uint16_t RLPXFrameWriter::MinFrameDequeLength =
h128::size * 4;
35 WriterState& qs = _priority ? m_q.first : m_q.second;
37 qs.
q.push_back(move(_p));
45 size_t RLPXFrameWriter::mux(
RLPXFrameCoder& _coder,
unsigned _size, deque<bytes>& o_toWrite)
48 static const size_t c_overhead = c_blockSize * 3;
49 if (_size < c_overhead + c_blockSize)
53 size_t frameLen = _size / 16 * 16;
55 bool swapQueues =
false;
56 while (frameLen >= c_overhead + c_blockSize)
58 bool highPending =
false;
59 bool lowPending =
false;
61 highPending = !!m_q.first.q.size();
63 lowPending = !!m_q.second.q.size();
65 if (!highPending && !lowPending)
69 bool high = highPending && !swapQueues ?
true : !lowPending;
71 size_t frameAllot = (!swapQueues && highPending && lowPending ? frameLen / 2 - (c_overhead + c_blockSize) > 0 ? frameLen / 2 : frameLen : frameLen) - c_overhead;
74 while (frameAllot >= c_blockSize)
121 frameAllot -= portion.size();
138 if (!payload.empty())
147 _coder.
writeFrame(m_protocolId, &payload, payload);
149 assert(frameLen >= payload.size());
150 frameLen -= payload.size();
151 o_toWrite.push_back(payload);
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
std::deque< RLPXPacket > q
bytes const & data() const
std::hash for asio::adress
assert(len-trim+(2 *lenIndices)<=WIDTH)
void writeFrame(uint16_t _protocolType, bytesConstRef _payload, bytes &o_bytes)
Write single-frame payload of packet(s).
#define DEV_GUARDED(MUTEX)
Simple block guard.
std::lock_guard< std::mutex > Guard
std::vector< byte > bytes
std::vector< unsigned char > toBytes() const
vector_ref< byte const > bytesConstRef
Queue and state for Writer Properties are used independently; only valid packets should be added to q...
uint8_t const size_t const size
bytes const & type() const
Class for writing to an RLP bytestream.
Encoder/decoder transport for RLPx connection established by RLPXHandshake.