print peer logs directly into the allocation
This commit is contained in:
parent
40c343be93
commit
b1e36a53e3
|
@ -2150,6 +2150,10 @@ namespace libtorrent
|
|||
, tcp::endpoint const& i, peer_id const& pi
|
||||
, peer_log_alert::direction_t dir
|
||||
, char const* event, char const* log);
|
||||
peer_log_alert(aux::stack_allocator& alloc, torrent_handle const& h
|
||||
, tcp::endpoint const& i, peer_id const& pi
|
||||
, peer_log_alert::direction_t dir
|
||||
, char const* event, char const* fmt, va_list v);
|
||||
|
||||
TORRENT_DEFINE_ALERT(peer_log_alert, 81)
|
||||
|
||||
|
|
|
@ -63,29 +63,48 @@ namespace libtorrent { namespace aux
|
|||
return ret;
|
||||
}
|
||||
|
||||
int copy_buffer(char const* buf, int size)
|
||||
int format_string(char const* fmt, va_list v)
|
||||
{
|
||||
int ret = int(m_storage.size());
|
||||
int const ret = int(m_storage.size());
|
||||
m_storage.resize(ret + 512);
|
||||
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wformat-nonliteral"
|
||||
#endif
|
||||
int const len = std::vsnprintf(m_storage.data() + ret, 512, fmt, v);
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
|
||||
m_storage.resize(len > 512 ? 512 : len);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int copy_buffer(char const* buf, int const size)
|
||||
{
|
||||
int const ret = int(m_storage.size());
|
||||
m_storage.resize(ret + size);
|
||||
memcpy(&m_storage[ret], buf, size);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int allocate(int bytes)
|
||||
int allocate(int const bytes)
|
||||
{
|
||||
TORRENT_ASSERT(bytes >= 0);
|
||||
int ret = int(m_storage.size());
|
||||
m_storage.resize(ret + bytes);
|
||||
return ret;
|
||||
}
|
||||
|
||||
char* ptr(int idx)
|
||||
char* ptr(int const idx)
|
||||
{
|
||||
TORRENT_ASSERT(idx >= 0);
|
||||
TORRENT_ASSERT(idx < int(m_storage.size()));
|
||||
return &m_storage[idx];
|
||||
}
|
||||
|
||||
char const* ptr(int idx) const
|
||||
char const* ptr(int const idx) const
|
||||
{
|
||||
TORRENT_ASSERT(idx >= 0);
|
||||
TORRENT_ASSERT(idx < int(m_storage.size()));
|
||||
|
|
|
@ -1699,6 +1699,17 @@ namespace libtorrent {
|
|||
, m_str_idx(alloc.copy_string(log))
|
||||
{}
|
||||
|
||||
peer_log_alert::peer_log_alert(aux::stack_allocator& alloc
|
||||
, torrent_handle const& h
|
||||
, tcp::endpoint const& i, peer_id const& pi
|
||||
, peer_log_alert::direction_t dir
|
||||
, char const* event, char const* fmt, va_list v)
|
||||
: peer_alert(alloc, h, i, pi)
|
||||
, event_type(event)
|
||||
, direction(dir)
|
||||
, m_str_idx(alloc.format_string(fmt, v))
|
||||
{}
|
||||
|
||||
char const* peer_log_alert::msg() const
|
||||
{
|
||||
return m_alloc.get().ptr(m_str_idx);
|
||||
|
|
|
@ -509,18 +509,15 @@ namespace libtorrent
|
|||
va_list v;
|
||||
va_start(v, fmt);
|
||||
|
||||
// TODO: it would be neat to be able to print this straight into the
|
||||
// alert's stack allocator
|
||||
char buf[512];
|
||||
std::vsnprintf(buf, sizeof(buf), fmt, v);
|
||||
va_end(v);
|
||||
|
||||
torrent_handle h;
|
||||
boost::shared_ptr<torrent> t = m_torrent.lock();
|
||||
if (t) h = t->get_handle();
|
||||
|
||||
m_ses.alerts().emplace_alert<peer_log_alert>(
|
||||
h, m_remote, m_peer_id, direction, event, buf);
|
||||
h, m_remote, m_peer_id, direction, event, fmt, v);
|
||||
|
||||
va_end(v);
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in New Issue