lokinet/include/llarp/iwp/sendbuf.hpp
Jeff Becker 1a1f93c171
* more tun stuff
* use std::unique_ptr where bare pointers aren't absolutely required
2018-08-17 15:49:58 -04:00

80 lines
1.0 KiB
C++

#pragma once
#include <llarp/buffer.h>
#include <llarp/time.h>
#include <memory>
#include <queue>
struct sendbuf_t
{
sendbuf_t(size_t s) : sz(s)
{
_buf = new byte_t[s];
}
~sendbuf_t()
{
if(_buf)
delete[] _buf;
}
size_t sz;
byte_t priority = 255;
size_t
size() const
{
return sz;
}
byte_t *
data()
{
return _buf;
}
llarp_buffer_t
Buffer()
{
llarp_buffer_t buf;
buf.base = _buf;
buf.sz = sz;
buf.cur = buf.base;
return buf;
}
struct GetTime
{
llarp_time_t
operator()(const sendbuf_t *buf) const
{
return buf->timestamp;
}
};
struct PutTime
{
void
operator()(sendbuf_t *buf) const
{
buf->timestamp = llarp_time_now_ms();
}
};
struct Compare
{
bool
operator()(const std::unique_ptr< sendbuf_t > &left,
const std::unique_ptr< sendbuf_t > &right) const
{
return left->priority < right->priority;
}
};
llarp_time_t timestamp = 0;
private:
byte_t *_buf = nullptr;
};