unify some operation-enums and strings to use operation_t

This commit is contained in:
arvidn 2017-06-17 18:18:19 -04:00 committed by Arvid Norberg
parent ff8703e862
commit ff454a92d4
13 changed files with 315 additions and 197 deletions

View File

@ -290,6 +290,7 @@ void bind_alert()
}
enum_<operation_t>("operation_t")
.value("unknown", operation_t::unknown)
.value("bittorrent", operation_t::bittorrent)
.value("iocontrol", operation_t::iocontrol)
.value("getpeername", operation_t::getpeername)
@ -308,10 +309,27 @@ void bind_alert()
.value("connect", operation_t::connect)
.value("ssl_handshake", operation_t::ssl_handshake)
.value("get_interface", operation_t::get_interface)
.value("unknown", operation_t::unknown)
.value("sock_listen", operation_t::sock_listen)
.value("sock_bind_to_device", operation_t::sock_bind_to_device)
.value("sock_accept", operation_t::sock_accept)
.value("parse_address", operation_t::parse_address)
.value("enum_if", operation_t::enum_if)
.value("file_stat", operation_t::file_stat)
.value("file_copy", operation_t::file_copy)
.value("file_fallocate", operation_t::file_fallocate)
.value("file_hard_link", operation_t::file_hard_link)
.value("file_remove", operation_t::file_remove)
.value("file_rename", operation_t::file_rename)
.value("file_open", operation_t::file_open)
.value("mkdir", operation_t::mkdir)
.value("check_resume", operation_t::check_resume)
.value("exception", operation_t::exception)
.value("alloc_cache_piece", operation_t::alloc_cache_piece)
.value("partfile_move", operation_t::partfile_move)
.value("partfile_read", operation_t::partfile_read)
.value("partfile_write", operation_t::partfile_write)
;
class_<torrent_alert, bases<alert>, noncopyable>(
"torrent_alert", no_init)
.def_readonly("handle", &torrent_alert::handle)
@ -445,7 +463,10 @@ void bind_alert()
"storage_moved_failed_alert", no_init)
.def_readonly("error", &storage_moved_failed_alert::error)
.def("file_path", &storage_moved_failed_alert::file_path)
.def_readonly("op", &storage_moved_failed_alert::op)
#ifndef TORRENT_NO_DEPRECATE
.def_readonly("operation", &storage_moved_failed_alert::operation)
#endif
;
class_<torrent_deleted_alert, bases<torrent_alert>, noncopyable>(
@ -497,8 +518,9 @@ void bind_alert()
.def_readonly("port", &listen_failed_alert::port)
.def("listen_interface", &listen_failed_alert::listen_interface)
.def_readonly("error", &listen_failed_alert::error)
.def_readonly("operation", &listen_failed_alert::operation)
.def_readonly("op", &listen_failed_alert::op)
#ifndef TORRENT_NO_DEPRECATE
.def_readonly("operation", &listen_failed_alert::operation)
.def_readonly("sock_type", &listen_failed_alert::sock_type)
#endif
.def_readonly("socket_type", &listen_failed_alert::socket_type)

View File

@ -60,10 +60,6 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent {
// maps an operation id (from peer_error_alert and peer_disconnected_alert)
// to its name. See peer_connection for the constants
TORRENT_EXPORT char const* operation_name(operation_t op);
#ifndef TORRENT_NO_DEPRECATE
TORRENT_DEPRECATED_EXPORT char const* operation_name(int op);
#endif
@ -912,7 +908,7 @@ namespace libtorrent {
// internal
storage_moved_failed_alert(aux::stack_allocator& alloc
, torrent_handle const& h, error_code const& e, string_view file
, char const* op);
, operation_t op);
TORRENT_DEFINE_ALERT(storage_moved_failed_alert, 34)
@ -924,13 +920,13 @@ namespace libtorrent {
// If the error happened for a specific file, this returns its path.
char const* file_path() const;
// If the error happened in a specific disk operation this is a nullptr
// terminated string naming which one, otherwise it's nullptr.
char const* operation;
// this indicates what underlying operation caused the error
operation_t op;
private:
aux::allocation_slot m_file_idx;
#ifndef TORRENT_NO_DEPRECATE
public:
char const* TORRENT_DEPRECATED_MEMBER operation;
// If the error happened for a specific file, ``file`` is its path.
std::string TORRENT_DEPRECATED_MEMBER file;
#endif
@ -1116,7 +1112,7 @@ namespace libtorrent {
{
// internal
file_error_alert(aux::stack_allocator& alloc, error_code const& ec
, string_view file, char const* op, torrent_handle const& h);
, string_view file, operation_t op, torrent_handle const& h);
TORRENT_DEFINE_ALERT(file_error_alert, 43)
@ -1127,7 +1123,9 @@ namespace libtorrent {
// the error code describing the error.
error_code const error;
char const* operation;
// indicates which underlying operation caused the error
operation_t op;
// the file that experienced the error
char const* filename() const;
@ -1136,6 +1134,7 @@ namespace libtorrent {
aux::allocation_slot m_file_idx;
#ifndef TORRENT_NO_DEPRECATE
public:
char const* TORRENT_DEPRECATED_MEMBER operation;
// the path to the file that was accessed when the error occurred.
std::string TORRENT_DEPRECATED_MEMBER file;
std::string TORRENT_DEPRECATED_MEMBER msg;
@ -1268,18 +1267,18 @@ namespace libtorrent {
// internal
listen_failed_alert(aux::stack_allocator& alloc, string_view iface
, libtorrent::address const& listen_addr, int listen_port
, int op, error_code const& ec, libtorrent::socket_type_t t);
, operation_t op, error_code const& ec, libtorrent::socket_type_t t);
listen_failed_alert(aux::stack_allocator& alloc, string_view iface
, tcp::endpoint const& ep, int op, error_code const& ec
, tcp::endpoint const& ep, operation_t op, error_code const& ec
, libtorrent::socket_type_t t);
listen_failed_alert(aux::stack_allocator& alloc, string_view iface
, udp::endpoint const& ep, int op, error_code const& ec
, udp::endpoint const& ep, operation_t op, error_code const& ec
, libtorrent::socket_type_t t);
listen_failed_alert(aux::stack_allocator& alloc, string_view iface
, int op, error_code const& ec, libtorrent::socket_type_t t);
, operation_t op, error_code const& ec, libtorrent::socket_type_t t);
TORRENT_DEFINE_ALERT_PRIO(listen_failed_alert, 48)
@ -1292,13 +1291,8 @@ namespace libtorrent {
// the error the system returned
error_code const error;
enum op_t
{
parse_addr, open, bind, listen, get_socket_name, accept, enum_if, bind_to_device
};
// the specific low level operation that failed. See op_t.
int const operation;
// the underlying operation that failed
operation_t op;
// the type of listen socket this alert refers to.
libtorrent::socket_type_t const socket_type;
@ -1316,6 +1310,21 @@ namespace libtorrent {
aux::allocation_slot m_interface_idx;
#ifndef TORRENT_NO_DEPRECATE
public:
enum op_t
{
parse_addr TORRENT_DEPRECATED_ENUM,
open TORRENT_DEPRECATED_ENUM,
bind TORRENT_DEPRECATED_ENUM,
listen TORRENT_DEPRECATED_ENUM,
get_socket_name TORRENT_DEPRECATED_ENUM,
accept TORRENT_DEPRECATED_ENUM,
enum_if TORRENT_DEPRECATED_ENUM,
bind_to_device TORRENT_DEPRECATED_ENUM
};
// the specific low level operation that failed. See op_t.
int const TORRENT_DEPRECATED_MEMBER operation;
// the address and port libtorrent attempted to listen on
aux::noexcept_movable<tcp::endpoint> TORRENT_DEPRECATED_MEMBER endpoint;
@ -1882,7 +1891,7 @@ namespace libtorrent {
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#endif
#endif // TORRENT_NO_DEPRECATE
// The session_stats_alert is posted when the user requests session statistics by
// calling post_session_stats() on the session object. Its category is

View File

@ -40,6 +40,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <boost/system/system_error.hpp>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#include "libtorrent/units.hpp"
#include "libtorrent/operations.hpp"
namespace libtorrent {
@ -486,7 +487,6 @@ namespace libtorrent {
using boost::system::system_error;
#ifndef BOOST_NO_EXCEPTIONS
#ifndef TORRENT_NO_DEPRECATE
TORRENT_DEPRECATED
inline boost::system::error_category& get_libtorrent_category()
@ -503,8 +503,8 @@ namespace libtorrent {
// error happened on
struct TORRENT_EXPORT storage_error
{
storage_error(): file_idx(-1), operation(0) {}
explicit storage_error(error_code e): ec(e), file_idx(-1), operation(0) {}
storage_error(): file_idx(-1), operation(operation_t::unknown) {}
explicit storage_error(error_code e): ec(e), file_idx(-1), operation(operation_t::unknown) {}
explicit operator bool() const { return ec.value() != 0; }
@ -519,42 +519,13 @@ namespace libtorrent {
// A code from file_operation_t enum, indicating what
// kind of operation failed.
std::uint32_t operation:8;
enum file_operation_t {
none,
stat,
mkdir,
open,
rename,
remove,
copy,
read,
write,
fallocate,
alloc_cache_piece,
partfile_move,
partfile_read,
partfile_write,
check_resume,
hard_link,
exception
};
operation_t operation;
// 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
{
static char const* ops[] =
{
"", "stat", "mkdir", "open", "rename", "remove", "copy"
, "read", "write", "fallocate", "allocate cache piece"
, "partfile move", "partfile read", "partfile write"
, "check resume", "hard_link", "exception"
};
return ops[operation];
}
{ return operation_name(operation); }
};
}

View File

@ -42,9 +42,12 @@ namespace libtorrent {
// peer to disconnect
enum class operation_t : std::uint8_t
{
// the error was unexpected and it is unknown which operation caused it
unknown,
// this is used when the bittorrent logic
// determines to disconnect
bittorrent = 0,
bittorrent,
// a call to iocontrol failed
iocontrol,
@ -100,16 +103,51 @@ namespace libtorrent {
// a connection failed to satisfy the bind interface setting
get_interface,
// the error was unexpected and it is unknown which operation caused it
unknown,
// a call to listen() on a socket
sock_listen,
// a call to the ioctl to bind a socket to a specific network device or
// adaptor
sock_bind_to_device,
// a call to accept() on a socket
sock_accept,
// convert a string into a valid network address
parse_address,
// enumeration network devices or adapters
enum_if,
file_stat,
file_copy,
file_fallocate,
file_hard_link,
file_remove,
file_rename,
file_open,
mkdir,
check_resume,
exception,
alloc_cache_piece,
partfile_move,
partfile_read,
partfile_write,
};
// maps an operation id (from peer_error_alert and peer_disconnected_alert)
// to its name. See peer_connection for the constants
TORRENT_EXPORT char const* operation_name(operation_t op);
#ifndef TORRENT_NO_DEPRECATE
enum deprecated_operation_t : std::uint8_t
{
// the error was unexpected and it is unknown which operation caused it
op_unknown TORRENT_DEPRECATED_ENUM,
// this is used when the bittorrent logic
// determines to disconnect
op_bittorrent TORRENT_DEPRECATED_ENUM = 0,
op_bittorrent TORRENT_DEPRECATED_ENUM ,
// a call to iocontrol failed
op_iocontrol TORRENT_DEPRECATED_ENUM,
@ -164,9 +202,6 @@ namespace libtorrent {
// a connection failed to satisfy the bind interface setting
op_get_interface TORRENT_DEPRECATED_ENUM,
// the error was unexpected and it is unknown which operation caused it
op_unknown TORRENT_DEPRECATED_ENUM,
};
#endif

View File

@ -427,7 +427,7 @@ TORRENT_TEST(dead_peers)
, [&](lt::alert const* a, lt::session&) {
auto* e = alert_cast<peer_disconnected_alert>(a);
if (e
&& e->operation == op_connect
&& e->op == operation_t::connect
&& e->error == error_code(errors::timed_out))
{
++num_connect_timeout;

View File

@ -649,12 +649,13 @@ namespace libtorrent {
storage_moved_failed_alert::storage_moved_failed_alert(
aux::stack_allocator& alloc, torrent_handle const& h, error_code const& e
, string_view f, char const* op)
, string_view f, operation_t const op_)
: torrent_alert(alloc, h)
, error(e)
, operation(op)
, op(op_)
, m_file_idx(alloc.copy_string(f))
#ifndef TORRENT_NO_DEPRECATE
, operation(operation_name(op_))
, file(f)
#endif
{}
@ -667,7 +668,7 @@ namespace libtorrent {
std::string storage_moved_failed_alert::message() const
{
return torrent_alert::message() + " storage move failed. "
+ (operation?operation:"") + " (" + file_path() + "): "
+ operation_name(op) + " (" + file_path() + "): "
+ convert_from_native(error.message());
}
@ -763,56 +764,126 @@ namespace libtorrent {
namespace {
int sock_type_idx(socket_type_t type)
{
int idx =
static_cast<std::underlying_type<socket_type_t>::type>(type);
TORRENT_ASSERT(0 <= idx && idx < 6);
return idx;
}
char const* sock_type_str(socket_type_t type)
{
static char const* type_str[] =
{ "TCP", "TCP/SSL", "UDP", "I2P", "Socks5", "uTP/SSL" };
return type_str[sock_type_idx(type)];
}
static char const* const nat_type_str[] = {"NAT-PMP", "UPnP"};
static char const* const protocol_str[] = {"TCP", "UDP"};
static char const* const socket_type_str[] = {
"null",
"TCP",
"Socks5/TCP",
"HTTP",
"uTP",
"i2p",
"SSL/TCP",
"SSL/Socks5",
"HTTPS",
"SSL/uTP"
};
int sock_type_idx(socket_type_t type)
{
int idx =
static_cast<std::underlying_type<socket_type_t>::type>(type);
TORRENT_ASSERT(0 <= idx && idx < 6);
return idx;
}
char const* sock_type_str(socket_type_t type)
{
static char const* type_str[] =
{ "TCP", "TCP/SSL", "UDP", "I2P", "Socks5", "uTP/SSL" };
return type_str[sock_type_idx(type)];
}
static char const* const nat_type_str[] = {"NAT-PMP", "UPnP"};
static char const* const protocol_str[] = {"TCP", "UDP"};
static char const* const socket_type_str[] = {
"null",
"TCP",
"Socks5/TCP",
"HTTP",
"uTP",
"i2p",
"SSL/TCP",
"SSL/Socks5",
"HTTPS",
"SSL/uTP"
};
#ifndef TORRENT_NO_DEPRECATE
int to_op_t(operation_t op)
{
using o = operation_t;
using lfo = listen_failed_alert::op_t;
// we have to use deprecated enum values here. suppress the warnings
#ifdef _MSC_VER
#pragma warning(push, 1)
// warning C4996: X: was declared deprecated
#pragma warning( disable : 4996 )
#endif
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
switch (op)
{
case o::bittorrent: return -1;
case o::iocontrol: return -1;
case o::getpeername: return -1;
case o::getname: return lfo::get_socket_name;
case o::alloc_recvbuf: return -1;
case o::alloc_sndbuf: return -1;
case o::file_write: return -1;
case o::file_read: return -1;
case o::file: return -1;
case o::sock_write: return -1;
case o::sock_read: return -1;
case o::sock_open: return lfo::open;
case o::sock_bind: return lfo::bind;
case o::available: return -1;
case o::encryption: return -1;
case o::connect: return -1;
case o::ssl_handshake: return -1;
case o::get_interface: return -1;
case o::unknown: return -1;
case o::sock_listen: return lfo::listen;
case o::sock_bind_to_device: return lfo::bind_to_device;
case o::sock_accept: return lfo::accept;
case o::parse_address: return lfo::parse_addr;
case o::enum_if: return lfo::enum_if;
case o::file_stat: return -1;
case o::file_copy: return -1;
case o::file_fallocate: return -1;
case o::file_hard_link: return -1;
case o::file_remove: return -1;
case o::file_rename: return -1;
case o::file_open: return -1;
case o::mkdir: return -1;
case o::check_resume: return -1;
case o::exception: return -1;
case o::alloc_cache_piece: return -1;
case o::partfile_move: return -1;
case o::partfile_read: return -1;
case o::partfile_write: return -1;
};
return -1;
}
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#endif // TORRENT_NO_DEPRECATE
} // anonymous namespace
listen_failed_alert::listen_failed_alert(
aux::stack_allocator& alloc
, string_view iface
, libtorrent::address const& listen_addr
, int listen_port
, int op
, operation_t const op_
, error_code const& ec
, libtorrent::socket_type_t t)
: error(ec)
, operation(op)
, op(op_)
, socket_type(t)
, address(listen_addr)
, port(listen_port)
, m_alloc(alloc)
, m_interface_idx(alloc.copy_string(iface))
#ifndef TORRENT_NO_DEPRECATE
, operation(to_op_t(op_))
, endpoint(listen_addr, std::uint16_t(listen_port))
, sock_type(static_cast<socket_type_t>(sock_type_idx(t)))
#endif
@ -822,14 +893,14 @@ namespace {
aux::stack_allocator& alloc
, string_view iface
, tcp::endpoint const& ep
, int op
, operation_t const op_
, error_code const& ec
, libtorrent::socket_type_t t)
: listen_failed_alert(alloc
, iface
, ep.address()
, ep.port()
, op
, op_
, ec
, t)
{}
@ -838,14 +909,14 @@ namespace {
aux::stack_allocator& alloc
, string_view iface
, udp::endpoint const& ep
, int op
, operation_t const op_
, error_code const& ec
, libtorrent::socket_type_t t)
: listen_failed_alert(alloc
, iface
, ep.address()
, ep.port()
, op
, op_
, ec
, t)
{}
@ -853,14 +924,14 @@ namespace {
listen_failed_alert::listen_failed_alert(
aux::stack_allocator& alloc
, string_view iface
, int op
, operation_t const op_
, error_code const& ec
, libtorrent::socket_type_t t)
: listen_failed_alert(alloc
, iface
, libtorrent::address()
, 0
, op
, op_
, ec
, t)
{}
@ -872,22 +943,11 @@ namespace {
std::string listen_failed_alert::message() const
{
static char const* op_str[] =
{
"parse_addr",
"open",
"bind",
"listen",
"get_socket_name",
"accept",
"enum_if",
"bind_to_device"
};
char ret[300];
std::snprintf(ret, sizeof(ret), "listening on %s (device: %s) failed: [%s] [%s] %s"
, print_endpoint(address, port).c_str()
, listen_interface()
, op_str[operation]
, operation_name(op)
, sock_type_str(socket_type)
, convert_from_native(error.message()).c_str());
return ret;
@ -1394,6 +1454,7 @@ namespace {
char const* operation_name(operation_t const op)
{
static char const* names[] = {
"unknown",
"bittorrent",
"iocontrol",
"getpeername",
@ -1412,7 +1473,25 @@ namespace {
"connect",
"ssl_handshake",
"get_interface",
"unknown",
"sock_listen",
"sock_bind_to_device",
"sock_accept",
"parse_address",
"enum_if",
"file_stat",
"file_copy",
"file_fallocate",
"file_hard_link",
"file_remove",
"file_rename",
"file_open",
"mkdir",
"check_resume",
"exception",
"alloc_cache_piece",
"partfile_move",
"partfile_read",
"partfile_write",
};
int const idx = static_cast<int>(op);
@ -1827,13 +1906,14 @@ namespace {
}
file_error_alert::file_error_alert(aux::stack_allocator& alloc
, error_code const& ec, string_view f, char const* op
, error_code const& ec, string_view f, operation_t const op_
, torrent_handle const& h)
: torrent_alert(alloc, h)
, error(ec)
, operation(op)
, op(op_)
, m_file_idx(alloc.copy_string(f))
#ifndef TORRENT_NO_DEPRECATE
, operation(operation_name(op_))
, file(f)
, msg(convert_from_native(error.message()))
#endif
@ -1847,7 +1927,7 @@ namespace {
std::string file_error_alert::message() const
{
return torrent_alert::message() + " "
+ (operation?operation:"") + " (" + filename()
+ operation_name(op) + " (" + filename()
+ ") error: " + convert_from_native(error.message());
}

View File

@ -1152,24 +1152,24 @@ namespace libtorrent {
{
ret = status_t::fatal_disk_error;
j->error.ec = err.code();
j->error.operation = storage_error::exception;
j->error.operation = operation_t::exception;
}
catch (std::bad_alloc const&)
{
ret = status_t::fatal_disk_error;
j->error.ec = errors::no_memory;
j->error.operation = storage_error::exception;
j->error.operation = operation_t::exception;
}
catch (std::exception const&)
{
ret = status_t::fatal_disk_error;
j->error.ec = boost::asio::error::fault;
j->error.operation = storage_error::exception;
j->error.operation = operation_t::exception;
}
// note that -2 errors are OK
TORRENT_ASSERT(ret != status_t::fatal_disk_error
|| (j->error.ec && j->error.operation != 0));
|| (j->error.ec && j->error.operation != operation_t::unknown));
m_stats_counters.inc_stats_counter(counters::num_running_disk_jobs, -1);
@ -1226,7 +1226,7 @@ namespace libtorrent {
if (buffer.get() == nullptr)
{
j->error.ec = error::no_memory;
j->error.operation = storage_error::alloc_cache_piece;
j->error.operation = operation_t::alloc_cache_piece;
return status_t::fatal_disk_error;
}
@ -1514,7 +1514,7 @@ namespace libtorrent {
!= boost::get<disk_buffer_holder>(j->argument).get());
TORRENT_ASSERT(pe->blocks[j->d.io.offset / 16 / 1024].buf != nullptr);
j->error.ec = error::operation_aborted;
j->error.operation = storage_error::write;
j->error.operation = operation_t::file_write;
return status_t::fatal_disk_error;
}
@ -1619,7 +1619,7 @@ namespace libtorrent {
else if (ret == -2)
{
j->error.ec = error::no_memory;
j->error.operation = storage_error::alloc_cache_piece;
j->error.operation = operation_t::alloc_cache_piece;
j->ret = status_t::fatal_disk_error;
return 0;
}
@ -1651,7 +1651,7 @@ namespace libtorrent {
{
j->ret = status_t::fatal_disk_error;
j->error.ec = error::no_memory;
j->error.operation = storage_error::read;
j->error.operation = operation_t::file_read;
return 0;
}
if (pe->outstanding_read)
@ -2254,7 +2254,7 @@ namespace libtorrent {
if (pe == nullptr)
{
j->error.ec = error::no_memory;
j->error.operation = storage_error::alloc_cache_piece;
j->error.operation = operation_t::alloc_cache_piece;
return status_t::fatal_disk_error;
}
@ -2352,7 +2352,7 @@ namespace libtorrent {
m_disk_cache.maybe_free_piece(pe);
j->error.ec = errors::no_memory;
j->error.operation = storage_error::alloc_cache_piece;
j->error.operation = operation_t::alloc_cache_piece;
return status_t::fatal_disk_error;
}
@ -2368,7 +2368,7 @@ namespace libtorrent {
if (read_ret < 0)
{
ret = status_t::fatal_disk_error;
TORRENT_ASSERT(j->error.ec && j->error.operation != 0);
TORRENT_ASSERT(j->error.ec && j->error.operation != operation_t::unknown);
m_disk_cache.free_buffer(iov.data());
break;
}
@ -2380,7 +2380,7 @@ namespace libtorrent {
{
ret = status_t::fatal_disk_error;
j->error.ec = boost::asio::error::eof;
j->error.operation = storage_error::read;
j->error.operation = operation_t::file_read;
m_disk_cache.free_buffer(iov.data());
break;
}
@ -2435,7 +2435,7 @@ namespace libtorrent {
m_disk_cache.maybe_free_piece(pe);
TORRENT_ASSERT(ret == status_t::no_error || (j->error.ec && j->error.operation != 0));
TORRENT_ASSERT(ret == status_t::no_error || (j->error.ec && j->error.operation != operation_t::unknown));
return ret;
}

View File

@ -5267,7 +5267,7 @@ namespace libtorrent {
if (t->alerts().should_post<file_error_alert>())
t->alerts().emplace_alert<file_error_alert>(error.ec
, t->resolve_filename(error.file())
, error.operation_str(), t->get_handle());
, error.operation, t->get_handle());
++m_disk_read_failures;
if (m_disk_read_failures > 100) disconnect(error.ec, operation_t::file_read);

View File

@ -1486,7 +1486,7 @@ namespace {
listen_socket_t ret;
ret.ssl = (flags & open_ssl_socket) != 0 ? transport::ssl : transport::plaintext;
ret.original_port = bind_ep.port();
int last_op = 0;
operation_t last_op = operation_t::unknown;
socket_type_t const sock_type
= (flags & open_ssl_socket)
? socket_type_t::tcp_ssl
@ -1500,7 +1500,7 @@ namespace {
{
ret.sock = std::make_shared<tcp::acceptor>(m_io_service);
ret.sock->open(bind_ep.protocol(), ec);
last_op = listen_failed_alert::open;
last_op = operation_t::sock_open;
if (ec)
{
#ifndef TORRENT_DISABLE_LOGGING
@ -1589,7 +1589,7 @@ namespace {
}
#endif // TORRENT_DISABLE_LOGGING
last_op = listen_failed_alert::bind_to_device;
last_op = operation_t::sock_bind_to_device;
if (m_alerts.should_post<listen_failed_alert>())
{
m_alerts.emplace_alert<listen_failed_alert>(device, bind_ep
@ -1601,7 +1601,7 @@ namespace {
}
ret.sock->bind(bind_ep, ec);
last_op = listen_failed_alert::bind;
last_op = operation_t::sock_bind;
while (ec == error_code(error::address_in_use) && retries > 0)
{
@ -1631,7 +1631,7 @@ namespace {
bind_ep.port(0);
ec.clear();
ret.sock->bind(bind_ep, ec);
last_op = listen_failed_alert::bind;
last_op = operation_t::sock_bind;
}
if (ec)
@ -1658,7 +1658,7 @@ namespace {
}
ret.local_endpoint = ret.sock->local_endpoint(ec);
ret.device = device;
last_op = listen_failed_alert::get_socket_name;
last_op = operation_t::getname;
if (ec)
{
#ifndef TORRENT_DISABLE_LOGGING
@ -1680,7 +1680,7 @@ namespace {
|| bind_ep.port() == 0);
ret.sock->listen(m_settings.get_int(settings_pack::listen_queue_size), ec);
last_op = listen_failed_alert::listen;
last_op = operation_t::sock_listen;
if (ec)
{
@ -1718,7 +1718,7 @@ namespace {
}
#endif
last_op = listen_failed_alert::open;
last_op = operation_t::sock_open;
if (m_alerts.should_post<listen_failed_alert>())
m_alerts.emplace_alert<listen_failed_alert>(device
, bind_ep, last_op, ec, udp_sock_type);
@ -1740,7 +1740,7 @@ namespace {
}
#endif // TORRENT_DISABLE_LOGGING
last_op = listen_failed_alert::bind_to_device;
last_op = operation_t::sock_bind_to_device;
if (m_alerts.should_post<listen_failed_alert>())
{
m_alerts.emplace_alert<listen_failed_alert>(device, bind_ep
@ -1752,7 +1752,7 @@ namespace {
#endif
ret.udp_sock->sock.bind(udp_bind_ep, ec);
last_op = listen_failed_alert::bind;
last_op = operation_t::sock_bind;
if (ec)
{
#ifndef TORRENT_DISABLE_LOGGING
@ -1869,7 +1869,7 @@ namespace {
if (m_alerts.should_post<listen_failed_alert>())
{
m_alerts.emplace_alert<listen_failed_alert>(device
, listen_failed_alert::enum_if, err
, operation_t::enum_if, err
, socket_type_t::tcp);
}
return;
@ -1925,7 +1925,7 @@ namespace {
if (m_alerts.should_post<listen_failed_alert>())
{
m_alerts.emplace_alert<listen_failed_alert>(device
, listen_failed_alert::open
, operation_t::sock_open
, boost::asio::error::operation_not_supported
, socket_type_t::tcp_ssl);
}
@ -2312,7 +2312,7 @@ namespace {
if (m_alerts.should_post<listen_failed_alert>())
{
m_alerts.emplace_alert<listen_failed_alert>("i2p"
, listen_failed_alert::accept
, operation_t::sock_accept
, e, socket_type_t::i2p);
}
#ifndef TORRENT_DISABLE_LOGGING
@ -2665,7 +2665,7 @@ namespace {
{
error_code err;
m_alerts.emplace_alert<listen_failed_alert>(ep.address().to_string(err)
, ep, listen_failed_alert::accept, e
, ep, operation_t::sock_accept, e
, ssl == transport::ssl ? socket_type_t::tcp_ssl : socket_type_t::tcp);
}
return;

View File

@ -151,7 +151,7 @@ namespace libtorrent {
if (ec)
{
ec.file(i);
ec.operation = storage_error::partfile_write;
ec.operation = operation_t::partfile_write;
return;
}
}
@ -176,7 +176,7 @@ namespace libtorrent {
if (ec)
{
ec.file(i);
ec.operation = storage_error::partfile_read;
ec.operation = operation_t::partfile_read;
return;
}
// remove the file
@ -185,7 +185,7 @@ namespace libtorrent {
if (ec)
{
ec.file(i);
ec.operation = storage_error::remove;
ec.operation = operation_t::file_remove;
}
}
*/
@ -197,7 +197,7 @@ namespace libtorrent {
if (ec)
{
ec.file(file_index_t(-1));
ec.operation = storage_error::partfile_write;
ec.operation = operation_t::partfile_write;
}
}
@ -245,7 +245,7 @@ namespace libtorrent {
if (err && err != boost::system::errc::no_such_file_or_directory)
{
ec.file(file_index);
ec.operation = storage_error::stat;
ec.operation = operation_t::file_stat;
ec.ec = err;
break;
}
@ -267,7 +267,7 @@ namespace libtorrent {
if (ec.ec)
{
ec.file(file_index);
ec.operation = storage_error::mkdir;
ec.operation = operation_t::mkdir;
break;
}
}
@ -277,7 +277,7 @@ namespace libtorrent {
if (ec)
{
ec.file(file_index);
ec.operation = storage_error::fallocate;
ec.operation = operation_t::file_fallocate;
return;
}
@ -286,7 +286,7 @@ namespace libtorrent {
if (ec)
{
ec.file(file_index);
ec.operation = storage_error::fallocate;
ec.operation = operation_t::file_fallocate;
break;
}
}
@ -312,7 +312,7 @@ namespace libtorrent {
if (ec && ec.ec != boost::system::errc::no_such_file_or_directory)
{
ec.file(i);
ec.operation = storage_error::stat;
ec.operation = operation_t::file_stat;
m_stat_cache.clear();
return false;
}
@ -333,7 +333,7 @@ namespace libtorrent {
if (ec)
{
ec.file(file_index_t(-1));
ec.operation = storage_error::stat;
ec.operation = operation_t::file_stat;
return false;
}
return false;
@ -366,7 +366,7 @@ namespace libtorrent {
if (ec.ec)
{
ec.file(index);
ec.operation = storage_error::rename;
ec.operation = operation_t::file_rename;
return;
}
@ -381,7 +381,7 @@ namespace libtorrent {
if (ec)
{
ec.file(index);
ec.operation = storage_error::rename;
ec.operation = operation_t::file_rename;
return;
}
}
@ -389,7 +389,7 @@ namespace libtorrent {
{
// if exists fails, report that error
ec.file(index);
ec.operation = storage_error::rename;
ec.operation = operation_t::file_rename;
return;
}
@ -499,7 +499,7 @@ namespace libtorrent {
{
ec.ec = e;
ec.file(file_index);
ec.operation = storage_error::partfile_read;
ec.operation = operation_t::partfile_read;
return -1;
}
return ret;
@ -515,7 +515,7 @@ namespace libtorrent {
// set this unconditionally in case the upper layer would like to treat
// short reads as errors
ec.operation = storage_error::read;
ec.operation = operation_t::file_read;
// we either get an error or 0 or more bytes read
TORRENT_ASSERT(e || ret >= 0);
@ -562,7 +562,7 @@ namespace libtorrent {
{
ec.ec = e;
ec.file(file_index);
ec.operation = storage_error::partfile_write;
ec.operation = operation_t::partfile_write;
return -1;
}
return ret;
@ -582,7 +582,7 @@ namespace libtorrent {
// set this unconditionally in case the upper layer would like to treat
// short reads as errors
ec.operation = storage_error::write;
ec.operation = operation_t::file_write;
// we either get an error or 0 or more bytes read
TORRENT_ASSERT(e || ret >= 0);
@ -615,7 +615,7 @@ namespace libtorrent {
if (ec.ec)
{
ec.file(file);
ec.operation = storage_error::mkdir;
ec.operation = operation_t::mkdir;
return file_handle();
}
@ -626,7 +626,7 @@ namespace libtorrent {
if (ec.ec)
{
ec.file(file);
ec.operation = storage_error::open;
ec.operation = operation_t::file_open;
return file_handle();
}
TORRENT_ASSERT(h);
@ -653,7 +653,7 @@ namespace libtorrent {
{
ec.ec = e;
ec.file(file);
ec.operation = storage_error::fallocate;
ec.operation = operation_t::file_fallocate;
return h;
}
m_stat_cache.set_dirty(file);

View File

@ -223,7 +223,7 @@ namespace libtorrent { namespace aux {
{
ec.ec = err;
ec.file(i);
ec.operation = storage_error::stat;
ec.operation = operation_t::file_stat;
return { status_t::file_exist, save_path };
}
}
@ -242,7 +242,7 @@ namespace libtorrent { namespace aux {
{
ec.ec = err;
ec.file(file_index_t(-1));
ec.operation = storage_error::mkdir;
ec.operation = operation_t::mkdir;
return { status_t::fatal_disk_error, save_path };
}
}
@ -250,7 +250,7 @@ namespace libtorrent { namespace aux {
{
ec.ec = err;
ec.file(file_index_t(-1));
ec.operation = storage_error::stat;
ec.operation = operation_t::file_stat;
return { status_t::fatal_disk_error, save_path };
}
}
@ -300,7 +300,7 @@ namespace libtorrent { namespace aux {
{
ec.ec = e;
ec.file(i);
ec.operation = storage_error::rename;
ec.operation = operation_t::file_rename;
break;
}
}
@ -312,7 +312,7 @@ namespace libtorrent { namespace aux {
{
ec.ec = e;
ec.file(file_index_t(-1));
ec.operation = storage_error::partfile_move;
ec.operation = operation_t::partfile_move;
}
}
@ -419,7 +419,7 @@ namespace libtorrent { namespace aux {
}
}
delete_one_file(p, ec.ec);
if (ec) { ec.file(i); ec.operation = storage_error::remove; }
if (ec) { ec.file(i); ec.operation = operation_t::file_remove; }
}
// remove the directories. Reverse order to delete
@ -434,7 +434,7 @@ namespace libtorrent { namespace aux {
{
ec.file(file_index_t(-1));
ec.ec = error;
ec.operation = storage_error::remove;
ec.operation = operation_t::file_remove;
}
}
}
@ -448,7 +448,7 @@ namespace libtorrent { namespace aux {
{
ec.file(file_index_t(-1));
ec.ec = error;
ec.operation = storage_error::remove;
ec.operation = operation_t::file_remove;
}
}
}
@ -492,7 +492,7 @@ namespace libtorrent { namespace aux {
ec.ec = err;
ec.file(idx);
ec.operation = storage_error::hard_link;
ec.operation = operation_t::file_hard_link;
return false;
}
}
@ -528,14 +528,14 @@ namespace libtorrent { namespace aux {
{
ec.ec = error;
ec.file(file_index);
ec.operation = storage_error::stat;
ec.operation = operation_t::file_stat;
return false;
}
else
{
ec.ec = errors::mismatching_file_size;
ec.file(file_index);
ec.operation = storage_error::stat;
ec.operation = operation_t::file_stat;
return false;
}
}
@ -546,7 +546,7 @@ namespace libtorrent { namespace aux {
// the wrong size. Reject the resume data
ec.ec = errors::mismatching_file_size;
ec.file(file_index);
ec.operation = storage_error::check_resume;
ec.operation = operation_t::check_resume;
return false;
}

View File

@ -1037,8 +1037,8 @@ namespace libtorrent {
{
if (alerts().should_post<file_error_alert>())
alerts().emplace_alert<file_error_alert>(error.ec
, resolve_filename(error.file()), error.operation_str(), get_handle());
if (c) c->disconnect(errors::no_memory, operation_t::file);
, resolve_filename(error.file()), error.operation, get_handle());
if (c) c->disconnect(errors::no_memory, error.operation);
return;
}
@ -1047,7 +1047,7 @@ namespace libtorrent {
// notify the user of the error
if (alerts().should_post<file_error_alert>())
alerts().emplace_alert<file_error_alert>(error.ec
, resolve_filename(error.file()), error.operation_str(), get_handle());
, resolve_filename(error.file()), error.operation, get_handle());
// if a write operation failed, and future writes are likely to
// fail, while reads may succeed, just set the torrent to upload mode
@ -2294,7 +2294,7 @@ namespace libtorrent {
m_num_checked_pieces = piece_index_t{0};
if (m_ses.alerts().should_post<file_error_alert>())
m_ses.alerts().emplace_alert<file_error_alert>(error.ec,
resolve_filename(error.file()), error.operation_str(), get_handle());
resolve_filename(error.file()), error.operation, get_handle());
#ifndef TORRENT_DISABLE_LOGGING
if (should_log())
@ -7528,8 +7528,9 @@ namespace libtorrent {
if (m_abort)
{
if (alerts().should_post<storage_moved_failed_alert>())
alerts().emplace_alert<storage_moved_failed_alert>(get_handle(), boost::asio::error::operation_aborted
, "", "");
alerts().emplace_alert<storage_moved_failed_alert>(get_handle()
, boost::asio::error::operation_aborted
, "", operation_t::unknown);
return;
}
@ -7597,7 +7598,7 @@ namespace libtorrent {
{
if (alerts().should_post<storage_moved_failed_alert>())
alerts().emplace_alert<storage_moved_failed_alert>(get_handle(), error.ec
, resolve_filename(error.file()), error.operation_str());
, resolve_filename(error.file()), error.operation);
}
}
catch (...) { handle_exception(); }

View File

@ -98,9 +98,9 @@ void on_check_resume_data(status_t const status, storage_error const& error, boo
void print_error(char const* call, int ret, storage_error const& ec)
{
std::printf("%s: %s() returned: %d error: \"%s\" in file: %d operation: %d\n"
std::printf("%s: %s() returned: %d error: \"%s\" in file: %d operation: %s\n"
, time_now_string(), call, ret, ec.ec.message().c_str()
, static_cast<int>(ec.file()), ec.operation);
, static_cast<int>(ec.file()), operation_name(ec.operation));
}
void run_until(io_service& ios, bool const& done)
@ -1170,7 +1170,7 @@ struct test_error_fileop
ec.file(file_index);
ec.ec.assign(boost::system::errc::permission_denied
, boost::system::generic_category());
ec.operation = storage_error::read;
ec.operation = operation_t::file_read;
return -1;
}
return bufs_size(bufs);
@ -1304,7 +1304,7 @@ TORRENT_TEST(readwritev_error)
TEST_EQUAL(ret, -1);
TEST_EQUAL(static_cast<int>(ec.file()), 2);
TEST_EQUAL(ec.operation, storage_error::read);
TEST_CHECK(ec.operation == operation_t::file_read);
TEST_EQUAL(ec.ec, boost::system::errc::permission_denied);
std::printf("error: %s\n", ec.ec.message().c_str());
}