convert remaining alerts to use operation_t instead of string literal
This commit is contained in:
parent
ff454a92d4
commit
35491bc476
|
@ -7,6 +7,7 @@
|
|||
#include <libtorrent/alert_types.hpp>
|
||||
#include <libtorrent/piece_picker.hpp> // for piece_block
|
||||
#include <libtorrent/session_stats.hpp>
|
||||
#include <libtorrent/operations.hpp>
|
||||
#include <memory>
|
||||
#include "bytes.hpp"
|
||||
|
||||
|
@ -328,8 +329,11 @@ void bind_alert()
|
|||
.value("partfile_move", operation_t::partfile_move)
|
||||
.value("partfile_read", operation_t::partfile_read)
|
||||
.value("partfile_write", operation_t::partfile_write)
|
||||
.value("hostname_lookup", operation_t::hostname_lookup)
|
||||
;
|
||||
|
||||
def("operation_name", static_cast<char const*(*)(operation_t)>(<::operation_name));
|
||||
|
||||
class_<torrent_alert, bases<alert>, noncopyable>(
|
||||
"torrent_alert", no_init)
|
||||
.def_readonly("handle", &torrent_alert::handle)
|
||||
|
@ -605,11 +609,12 @@ void bind_alert()
|
|||
class_<fastresume_rejected_alert, bases<torrent_alert>, noncopyable>(
|
||||
"fastresume_rejected_alert", no_init)
|
||||
.def_readonly("error", &fastresume_rejected_alert::error)
|
||||
.def("file_path", &fastresume_rejected_alert::file_path)
|
||||
.def_readonly("op", &fastresume_rejected_alert::op)
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
.def_readonly("operation", &fastresume_rejected_alert::operation)
|
||||
.def_readonly("msg", &fastresume_rejected_alert::msg)
|
||||
#endif
|
||||
.def("file_path", &fastresume_rejected_alert::file_path)
|
||||
.def_readonly("operation", &fastresume_rejected_alert::operation)
|
||||
;
|
||||
|
||||
class_<peer_blocked_alert, bases<peer_alert>, noncopyable>(
|
||||
|
|
|
@ -529,6 +529,15 @@ class test_example_client(unittest.TestCase):
|
|||
default = lt.default_settings()
|
||||
print(default)
|
||||
|
||||
class test_operation_t(unittest.TestCase):
|
||||
|
||||
def test_enum(self):
|
||||
self.assertEqual(lt.operation_name(lt.operation_t.sock_accept), "sock_accept")
|
||||
self.assertEqual(lt.operation_name(lt.operation_t.unknown), "unknown")
|
||||
self.assertEqual(lt.operation_name(lt.operation_t.mkdir), "mkdir")
|
||||
self.assertEqual(lt.operation_name(lt.operation_t.partfile_write), "partfile_write")
|
||||
self.assertEqual(lt.operation_name(lt.operation_t.hostname_lookup), "hostname_lookup")
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(lt.__version__)
|
||||
shutil.copy(os.path.join('..', '..', 'test', 'test_torrents',
|
||||
|
|
|
@ -1488,7 +1488,7 @@ namespace libtorrent {
|
|||
// internal
|
||||
fastresume_rejected_alert(aux::stack_allocator& alloc
|
||||
, torrent_handle const& h, error_code const& ec, string_view file
|
||||
, char const* op);
|
||||
, operation_t op);
|
||||
|
||||
TORRENT_DEFINE_ALERT(fastresume_rejected_alert, 53)
|
||||
|
||||
|
@ -1501,14 +1501,17 @@ namespace libtorrent {
|
|||
// If the error happened to a specific file, this returns the path to it.
|
||||
char const* file_path() const;
|
||||
|
||||
// If the error happened in a disk operation. a 0-terminated string of
|
||||
// the name of that operation. ``operation`` is nullptr otherwise.
|
||||
char const* operation;
|
||||
// the underlying operation that failed
|
||||
operation_t op;
|
||||
|
||||
private:
|
||||
aux::allocation_slot m_path_idx;
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
public:
|
||||
// If the error happened in a disk operation. a 0-terminated string of
|
||||
// the name of that operation. ``operation`` is nullptr otherwise.
|
||||
char const* TORRENT_DEPRECATED_MEMBER operation;
|
||||
|
||||
// If the error happened to a specific file, ``file`` is the path to it.
|
||||
std::string TORRENT_DEPRECATED_MEMBER file;
|
||||
std::string TORRENT_DEPRECATED_MEMBER msg;
|
||||
|
@ -1989,7 +1992,8 @@ namespace libtorrent {
|
|||
struct TORRENT_EXPORT dht_error_alert final : alert
|
||||
{
|
||||
// internal
|
||||
dht_error_alert(aux::stack_allocator& alloc, int op, error_code const& ec);
|
||||
dht_error_alert(aux::stack_allocator& alloc, operation_t op
|
||||
, error_code const& ec);
|
||||
|
||||
TORRENT_DEFINE_ALERT(dht_error_alert, 73)
|
||||
|
||||
|
@ -1999,14 +2003,19 @@ namespace libtorrent {
|
|||
// the error code
|
||||
error_code error;
|
||||
|
||||
// the operation that failed
|
||||
operation_t op;
|
||||
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
enum op_t
|
||||
{
|
||||
unknown,
|
||||
hostname_lookup
|
||||
unknown TORRENT_DEPRECATED_ENUM,
|
||||
hostname_lookup TORRENT_DEPRECATED_ENUM
|
||||
};
|
||||
|
||||
// the operation that failed
|
||||
op_t const operation;
|
||||
op_t const TORRENT_DEPRECATED_MEMBER operation;
|
||||
#endif
|
||||
};
|
||||
|
||||
// this alert is posted as a response to a call to session::get_item(),
|
||||
|
|
|
@ -521,11 +521,13 @@ namespace libtorrent {
|
|||
// kind of operation failed.
|
||||
operation_t operation;
|
||||
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
// Returns a string literal representing the file operation
|
||||
// that failed. If there were no failure, it returns
|
||||
// an empty string.
|
||||
char const* operation_str() const
|
||||
char const* operation_str() const TORRENT_DEPRECATED_MEMBER
|
||||
{ return operation_name(operation); }
|
||||
#endif
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -133,6 +133,7 @@ namespace libtorrent {
|
|||
partfile_move,
|
||||
partfile_read,
|
||||
partfile_write,
|
||||
hostname_lookup,
|
||||
};
|
||||
|
||||
// maps an operation id (from peer_error_alert and peer_disconnected_alert)
|
||||
|
|
|
@ -854,6 +854,7 @@ namespace {
|
|||
case o::partfile_move: return -1;
|
||||
case o::partfile_read: return -1;
|
||||
case o::partfile_write: return -1;
|
||||
case o::hostname_lookup: return -1;
|
||||
};
|
||||
return -1;
|
||||
}
|
||||
|
@ -1092,12 +1093,13 @@ namespace {
|
|||
, torrent_handle const& h
|
||||
, error_code const& ec
|
||||
, string_view f
|
||||
, char const* op)
|
||||
, operation_t const op_)
|
||||
: torrent_alert(alloc, h)
|
||||
, error(ec)
|
||||
, operation(op)
|
||||
, op(op_)
|
||||
, m_path_idx(alloc.copy_string(f))
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
, operation(operation_name(op_))
|
||||
, file(f)
|
||||
, msg(convert_from_native(error.message()))
|
||||
#endif
|
||||
|
@ -1107,7 +1109,7 @@ namespace {
|
|||
std::string fastresume_rejected_alert::message() const
|
||||
{
|
||||
return torrent_alert::message() + " fast resume rejected. "
|
||||
+ (operation?operation:"") + "(" + file_path() + "): "
|
||||
+ operation_name(op) + "(" + file_path() + "): "
|
||||
+ convert_from_native(error.message());
|
||||
}
|
||||
|
||||
|
@ -1492,6 +1494,7 @@ namespace {
|
|||
"partfile_move",
|
||||
"partfile_read",
|
||||
"partfile_write",
|
||||
"hostname_lookup"
|
||||
};
|
||||
|
||||
int const idx = static_cast<int>(op);
|
||||
|
@ -1575,26 +1578,22 @@ namespace {
|
|||
return buf;
|
||||
}
|
||||
|
||||
dht_error_alert::dht_error_alert(aux::stack_allocator&, int op
|
||||
dht_error_alert::dht_error_alert(aux::stack_allocator&
|
||||
, operation_t const op_
|
||||
, error_code const& ec)
|
||||
: error(ec), operation(op_t(op))
|
||||
: error(ec)
|
||||
, op(op_)
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
, operation(op_ == operation_t::hostname_lookup
|
||||
? op_t::hostname_lookup : op_t::unknown)
|
||||
#endif
|
||||
{}
|
||||
|
||||
std::string dht_error_alert::message() const
|
||||
{
|
||||
static const char* const operation_names[] =
|
||||
{
|
||||
"unknown",
|
||||
"hostname lookup"
|
||||
};
|
||||
|
||||
int op = operation;
|
||||
if (op < 0 || op >= int(sizeof(operation_names)/sizeof(operation_names[0])))
|
||||
op = 0;
|
||||
|
||||
char msg[600];
|
||||
std::snprintf(msg, sizeof(msg), "DHT error [%s] (%d) %s"
|
||||
, operation_names[op]
|
||||
, operation_name(op)
|
||||
, error.value()
|
||||
, convert_from_native(error.message()).c_str());
|
||||
return msg;
|
||||
|
|
|
@ -5782,7 +5782,7 @@ namespace {
|
|||
{
|
||||
if (m_alerts.should_post<dht_error_alert>())
|
||||
m_alerts.emplace_alert<dht_error_alert>(
|
||||
dht_error_alert::hostname_lookup, e);
|
||||
operation_t::hostname_lookup, e);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -5812,7 +5812,7 @@ namespace {
|
|||
{
|
||||
if (m_alerts.should_post<dht_error_alert>())
|
||||
m_alerts.emplace_alert<dht_error_alert>(
|
||||
dht_error_alert::hostname_lookup, e);
|
||||
operation_t::hostname_lookup, e);
|
||||
|
||||
if (m_outstanding_router_lookups == 0) update_dht();
|
||||
return;
|
||||
|
|
|
@ -595,7 +595,8 @@ namespace libtorrent {
|
|||
&& m_ses.alerts().should_post<fastresume_rejected_alert>())
|
||||
{
|
||||
m_ses.alerts().emplace_alert<fastresume_rejected_alert>(get_handle()
|
||||
, m_add_torrent_params->internal_resume_data_error, "", "");
|
||||
, m_add_torrent_params->internal_resume_data_error, ""
|
||||
, operation_t::unknown);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1028,7 +1029,8 @@ namespace libtorrent {
|
|||
{
|
||||
debug_log("disk error: (%d) %s [%*s : %s] in file: %s"
|
||||
, error.ec.value(), error.ec.message().c_str()
|
||||
, int(job_name.size()), job_name.data(), error.operation_str()
|
||||
, int(job_name.size()), job_name.data()
|
||||
, operation_name(error.operation)
|
||||
, resolve_filename(error.file()).c_str());
|
||||
}
|
||||
#endif
|
||||
|
@ -1982,7 +1984,7 @@ namespace libtorrent {
|
|||
m_ses.alerts().emplace_alert<fastresume_rejected_alert>(get_handle()
|
||||
, error.ec
|
||||
, resolve_filename(error.file())
|
||||
, error.operation_str());
|
||||
, error.operation);
|
||||
}
|
||||
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
|
|
Loading…
Reference in New Issue