add error_code to torrent_status instead of error string
This commit is contained in:
parent
4911a85761
commit
ebb9fdaf54
|
@ -97,7 +97,11 @@ void bind_torrent_status()
|
|||
.def_readonly("upload_mode", &torrent_status::upload_mode)
|
||||
.def_readonly("share_mode", &torrent_status::share_mode)
|
||||
.def_readonly("super_seeding", &torrent_status::super_seeding)
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
.def_readonly("error", &torrent_status::error)
|
||||
#endif
|
||||
.def_readonly("errc", &torrent_status::errc)
|
||||
.def_readonly("error_file", &torrent_status::error_file)
|
||||
.def_readonly("priority", &torrent_status::priority)
|
||||
.def_readonly("added_time", &torrent_status::added_time)
|
||||
.def_readonly("completed_time", &torrent_status::completed_time)
|
||||
|
|
|
@ -10,7 +10,7 @@ std::string torrent_state(lt::torrent_status const& s)
|
|||
{"checking (q)", "checking", "dl metadata"
|
||||
, "downloading", "finished", "seeding", "allocating", "checking (r)"};
|
||||
|
||||
if (!s.error.empty()) return s.error;
|
||||
if (s.errc) return s.errc.message();
|
||||
std::string ret;
|
||||
if (s.paused && !s.auto_managed) ret += "paused";
|
||||
else if (s.paused && s.auto_managed) ret += "queued";
|
||||
|
@ -307,7 +307,7 @@ void torrent_view::print_torrent(lt::torrent_status const& s, bool selected)
|
|||
if (name.size() > 50) name.resize(50);
|
||||
|
||||
color_code progress_bar_color = col_yellow;
|
||||
if (!s.error.empty()) progress_bar_color = col_red;
|
||||
if (s.errc) progress_bar_color = col_red;
|
||||
else if (s.paused) progress_bar_color = col_blue;
|
||||
else if (s.state == lt::torrent_status::downloading_metadata)
|
||||
progress_bar_color = col_magenta;
|
||||
|
|
|
@ -451,21 +451,6 @@ namespace libtorrent
|
|||
void handle_disk_error(disk_io_job const* j, peer_connection* c = 0);
|
||||
void clear_error();
|
||||
|
||||
enum {
|
||||
// the error did not occur on a file
|
||||
error_file_none = -1,
|
||||
|
||||
// the error occurred on m_url
|
||||
error_file_url = -2,
|
||||
|
||||
// the error occurred setting up the SSL context
|
||||
error_file_ssl_ctx = -3,
|
||||
|
||||
// the error occurred while loading the .torrent file via the user
|
||||
// supplied load function
|
||||
error_file_metadata = -4
|
||||
};
|
||||
|
||||
void set_error(error_code const& ec, int file);
|
||||
bool has_error() const { return !!m_error; }
|
||||
error_code error() const { return m_error; }
|
||||
|
|
|
@ -117,11 +117,36 @@ namespace libtorrent
|
|||
checking_resume_data
|
||||
};
|
||||
|
||||
// may be set to an error message describing why the torrent
|
||||
// was paused, in case it was paused by an error. If the torrent
|
||||
// is not paused or if it's paused but not because of an error,
|
||||
// this string is empty.
|
||||
// may be set to an error code describing why the torrent was paused, in
|
||||
// case it was paused by an error. If the torrent is not paused or if it's
|
||||
// paused but not because of an error, this error_code is not set.
|
||||
// if the error is attributed specifically to a file, error_file is set to
|
||||
// the index of that file in the .torrent file.
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
std::string error;
|
||||
#else
|
||||
std::string _dummy_string_;
|
||||
#endif
|
||||
error_code errc;
|
||||
int error_file;
|
||||
|
||||
|
||||
// special values for error_file to describe which file or component
|
||||
// encountered the error (``errc``).
|
||||
enum error_file_t {
|
||||
// the error did not occur on a file
|
||||
error_file_none = -1,
|
||||
|
||||
// the error occurred on m_url
|
||||
error_file_url = -2,
|
||||
|
||||
// the error occurred setting up the SSL context
|
||||
error_file_ssl_ctx = -3,
|
||||
|
||||
// the error occurred while loading the .torrent file via the user
|
||||
// supplied load function
|
||||
error_file_metadata = -4
|
||||
};
|
||||
|
||||
// the path to the directory where this torrent's files are stored.
|
||||
// It's typically the path as was given to async_add_torrent() or
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 8488578e25b14f859499abb89106ff61b3b1b299
|
||||
Subproject commit 0901c6cfded385820ef7072e373a7e11e647923a
|
|
@ -1514,7 +1514,7 @@ namespace aux {
|
|||
m_user_load_torrent(t->info_hash(), buffer, ec);
|
||||
if (ec)
|
||||
{
|
||||
t->set_error(ec, torrent::error_file_metadata);
|
||||
t->set_error(ec, torrent_status::error_file_metadata);
|
||||
t->pause(false);
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -214,7 +214,7 @@ namespace libtorrent
|
|||
, m_checking_piece(0)
|
||||
, m_num_checked_pieces(0)
|
||||
, m_refcount(0)
|
||||
, m_error_file(error_file_none)
|
||||
, m_error_file(torrent_status::error_file_none)
|
||||
, m_average_piece_time(0)
|
||||
, m_piece_time_deviation(0)
|
||||
, m_total_failed_bytes(0)
|
||||
|
@ -561,14 +561,14 @@ namespace libtorrent
|
|||
|
||||
if (ec && ec != boost::asio::error::eof)
|
||||
{
|
||||
set_error(ec, error_file_url);
|
||||
set_error(ec, torrent_status::error_file_url);
|
||||
pause();
|
||||
return;
|
||||
}
|
||||
|
||||
if (parser.status_code() != 200)
|
||||
{
|
||||
set_error(error_code(parser.status_code(), get_http_category()), error_file_url);
|
||||
set_error(error_code(parser.status_code(), get_http_category()), torrent_status::error_file_url);
|
||||
pause();
|
||||
return;
|
||||
}
|
||||
|
@ -577,7 +577,7 @@ namespace libtorrent
|
|||
boost::shared_ptr<torrent_info> tf(boost::make_shared<torrent_info>(data, size, boost::ref(e), 0));
|
||||
if (e)
|
||||
{
|
||||
set_error(e, error_file_url);
|
||||
set_error(e, torrent_status::error_file_url);
|
||||
pause();
|
||||
return;
|
||||
}
|
||||
|
@ -617,7 +617,7 @@ namespace libtorrent
|
|||
// TODO: if the existing torrent doesn't have metadata, insert
|
||||
// the metadata we just downloaded into it.
|
||||
|
||||
set_error(error_code(errors::duplicate_torrent, get_libtorrent_category()), error_file_url);
|
||||
set_error(error_code(errors::duplicate_torrent, get_libtorrent_category()), torrent_status::error_file_url);
|
||||
abort();
|
||||
return;
|
||||
}
|
||||
|
@ -1666,7 +1666,7 @@ namespace libtorrent
|
|||
{
|
||||
error_code ec(::ERR_get_error(),
|
||||
boost::asio::error::get_ssl_category());
|
||||
set_error(ec, error_file_ssl_ctx);
|
||||
set_error(ec, torrent_status::error_file_ssl_ctx);
|
||||
pause();
|
||||
return;
|
||||
}
|
||||
|
@ -1681,7 +1681,7 @@ namespace libtorrent
|
|||
| context::verify_client_once, ec);
|
||||
if (ec)
|
||||
{
|
||||
set_error(ec, error_file_ssl_ctx);
|
||||
set_error(ec, torrent_status::error_file_ssl_ctx);
|
||||
pause();
|
||||
return;
|
||||
}
|
||||
|
@ -1692,7 +1692,7 @@ namespace libtorrent
|
|||
ctx->set_verify_callback(boost::bind(&torrent::verify_peer_cert, this, _1, _2), ec);
|
||||
if (ec)
|
||||
{
|
||||
set_error(ec, error_file_ssl_ctx);
|
||||
set_error(ec, torrent_status::error_file_ssl_ctx);
|
||||
pause();
|
||||
return;
|
||||
}
|
||||
|
@ -1704,7 +1704,7 @@ namespace libtorrent
|
|||
{
|
||||
ec.assign(::ERR_get_error(),
|
||||
boost::asio::error::get_ssl_category());
|
||||
set_error(ec, error_file_ssl_ctx);
|
||||
set_error(ec, torrent_status::error_file_ssl_ctx);
|
||||
pause();
|
||||
return;
|
||||
}
|
||||
|
@ -1725,7 +1725,7 @@ namespace libtorrent
|
|||
ec.assign(::ERR_get_error(),
|
||||
boost::asio::error::get_ssl_category());
|
||||
X509_STORE_free(cert_store);
|
||||
set_error(ec, error_file_ssl_ctx);
|
||||
set_error(ec, torrent_status::error_file_ssl_ctx);
|
||||
pause();
|
||||
return;
|
||||
}
|
||||
|
@ -1750,7 +1750,7 @@ namespace libtorrent
|
|||
// tell the client we need a cert for this torrent
|
||||
alerts().emplace_alert<torrent_need_cert_alert>(get_handle());
|
||||
#else
|
||||
set_error(boost::asio::error::operation_not_supported, error_file_ssl_ctx);
|
||||
set_error(boost::asio::error::operation_not_supported, torrent_status::error_file_ssl_ctx);
|
||||
pause();
|
||||
#endif
|
||||
}
|
||||
|
@ -1835,14 +1835,14 @@ namespace libtorrent
|
|||
|
||||
if (m_torrent_file->num_pieces() > piece_picker::max_pieces)
|
||||
{
|
||||
set_error(errors::too_many_pieces_in_torrent, error_file_none);
|
||||
set_error(errors::too_many_pieces_in_torrent, torrent_status::error_file_none);
|
||||
pause();
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_torrent_file->num_pieces() == 0)
|
||||
{
|
||||
set_error(errors::torrent_invalid_length, error_file_none);
|
||||
set_error(errors::torrent_invalid_length, torrent_status::error_file_none);
|
||||
pause();
|
||||
return;
|
||||
}
|
||||
|
@ -2175,7 +2175,7 @@ namespace libtorrent
|
|||
m_torrent_file->load(&buffer[0], buffer.size(), ec);
|
||||
if (ec)
|
||||
{
|
||||
set_error(ec, error_file_metadata);
|
||||
set_error(ec, torrent_status::error_file_metadata);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -7735,7 +7735,7 @@ namespace libtorrent
|
|||
{
|
||||
alerts().emplace_alert<metadata_failed_alert>(get_handle(), ec);
|
||||
}
|
||||
set_error(errors::invalid_swarm_metadata, error_file_none);
|
||||
set_error(errors::invalid_swarm_metadata, torrent_status::error_file_none);
|
||||
pause();
|
||||
return false;
|
||||
}
|
||||
|
@ -9213,7 +9213,7 @@ namespace libtorrent
|
|||
bool checking_files = should_check_files();
|
||||
m_ses.trigger_auto_manage();
|
||||
m_error = error_code();
|
||||
m_error_file = error_file_none;
|
||||
m_error_file = torrent_status::error_file_none;
|
||||
|
||||
update_gauge();
|
||||
state_updated();
|
||||
|
@ -9233,10 +9233,10 @@ namespace libtorrent
|
|||
}
|
||||
std::string torrent::resolve_filename(int file) const
|
||||
{
|
||||
if (file == error_file_none) return "";
|
||||
if (file == error_file_url) return m_url;
|
||||
if (file == error_file_ssl_ctx) return "SSL Context";
|
||||
if (file == error_file_metadata) return "metadata (from user load function)";
|
||||
if (file == torrent_status::error_file_none) return "";
|
||||
if (file == torrent_status::error_file_url) return m_url;
|
||||
if (file == torrent_status::error_file_ssl_ctx) return "SSL Context";
|
||||
if (file == torrent_status::error_file_metadata) return "metadata (from user load function)";
|
||||
|
||||
if (m_storage && file >= 0)
|
||||
{
|
||||
|
@ -11778,8 +11778,13 @@ namespace libtorrent
|
|||
st->torrent_file = m_torrent_file;
|
||||
|
||||
st->has_incoming = m_has_incoming;
|
||||
st->errc = m_error;
|
||||
st->error_file = m_error_file;
|
||||
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
if (m_error) st->error = convert_from_native(m_error.message())
|
||||
+ ": " + resolve_filename(m_error_file);
|
||||
#endif
|
||||
st->seed_mode = m_seed_mode;
|
||||
st->moving_storage = m_moving_storage;
|
||||
|
||||
|
|
|
@ -367,7 +367,7 @@ void print_ses_rate(float time
|
|||
, int(st1->progress * 100)
|
||||
, st1->num_peers
|
||||
, st1->connect_candidates
|
||||
, st1->error.empty() ? "" : (" [" + st1->error + "]").c_str());
|
||||
, st1->errc ? (" [" + st1->errc.message() + "]").c_str() : "");
|
||||
}
|
||||
if (st2)
|
||||
fprintf(stderr, " : %3.1fs | %dkB/s %dkB/s %d%% %d cc:%d%s", time
|
||||
|
@ -376,7 +376,7 @@ void print_ses_rate(float time
|
|||
, int(st2->progress * 100)
|
||||
, st2->num_peers
|
||||
, st2->connect_candidates
|
||||
, st2->error.empty() ? "" : (" [" + st2->error + "]").c_str());
|
||||
, st2->errc ? (" [" + st1->errc.message() + "]").c_str() : "");
|
||||
if (st3)
|
||||
fprintf(stderr, " : %3.1fs | %dkB/s %dkB/s %d%% %d cc:%d%s", time
|
||||
, int(st3->download_payload_rate / 1000)
|
||||
|
@ -384,7 +384,7 @@ void print_ses_rate(float time
|
|||
, int(st3->progress * 100)
|
||||
, st3->num_peers
|
||||
, st3->connect_candidates
|
||||
, st3->error.empty() ? "" : (" [" + st3->error + "]").c_str());
|
||||
, st3->errc ? (" [" + st1->errc.message() + "]").c_str() : "");
|
||||
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
|
|
@ -202,7 +202,7 @@ void test_checking(int flags = read_only_files)
|
|||
|
||||
st = tor1.status();
|
||||
|
||||
printf("%d %f %s\n", st.state, st.progress_ppm / 10000.f, st.error.c_str());
|
||||
printf("%d %f %s\n", st.state, st.progress_ppm / 10000.f, st.errc.message().c_str());
|
||||
|
||||
if (
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
|
@ -212,7 +212,7 @@ void test_checking(int flags = read_only_files)
|
|||
&& st.state != torrent_status::checking_resume_data)
|
||||
break;
|
||||
|
||||
if (!st.error.empty()) break;
|
||||
if (!st.errc) break;
|
||||
test_sleep(500);
|
||||
}
|
||||
if (flags & incomplete_files)
|
||||
|
@ -233,33 +233,32 @@ void test_checking(int flags = read_only_files)
|
|||
// we expect our checking of the files to trigger
|
||||
// attempts to truncate them, since the files are
|
||||
// read-only here, we expect the checking to fail.
|
||||
TEST_CHECK(!st.error.empty());
|
||||
if (!st.error.empty())
|
||||
fprintf(stderr, "error: %s\n", st.error.c_str());
|
||||
TEST_CHECK(st.errc);
|
||||
if (st.errc)
|
||||
fprintf(stderr, "error: %s\n", st.errc.message().c_str());
|
||||
|
||||
// wait a while to make sure libtorrent survived the error
|
||||
test_sleep(1000);
|
||||
|
||||
st = tor1.status();
|
||||
TEST_CHECK(!st.is_seeding);
|
||||
TEST_CHECK(!st.error.empty());
|
||||
if (!st.error.empty())
|
||||
fprintf(stderr, "error: %s\n", st.error.c_str());
|
||||
TEST_CHECK(!st.errc);
|
||||
if (st.errc)
|
||||
fprintf(stderr, "error: %s\n", st.errc.message().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
TEST_CHECK(st.error.empty());
|
||||
if (!st.error.empty())
|
||||
fprintf(stderr, "error: %s\n", st.error.c_str());
|
||||
TEST_CHECK(!st.errc);
|
||||
if (st.errc)
|
||||
fprintf(stderr, "error: %s\n", st.errc.message().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
if ((flags & (incomplete_files | corrupt_files)) == 0)
|
||||
{
|
||||
TEST_CHECK(st.is_seeding);
|
||||
if (!st.error.empty())
|
||||
fprintf(stderr, "ERROR: %s\n", st.error.c_str());
|
||||
TEST_CHECK(st.error.empty());
|
||||
if (st.errc)
|
||||
fprintf(stderr, "error: %s\n", st.errc.message().c_str());
|
||||
}
|
||||
|
||||
// make the files writable again
|
||||
|
|
|
@ -312,9 +312,9 @@ void test_transfer(int proxy_type, settings_pack const& sett
|
|||
print_alerts(ses1, "ses1", true, true, true, &on_alert);
|
||||
print_alerts(ses2, "ses2", true, true, true, &on_alert);
|
||||
|
||||
std::string err = tor2.status().error;
|
||||
fprintf(stderr, "error: \"%s\"\n", err.c_str());
|
||||
TEST_CHECK(err.empty());
|
||||
lt::error_code err = tor2.status().errc;
|
||||
fprintf(stderr, "error: \"%s\"\n", err.message().c_str());
|
||||
TEST_CHECK(!err);
|
||||
tor2.set_upload_mode(false);
|
||||
|
||||
// at this point we probably disconnected the seed
|
||||
|
@ -338,7 +338,7 @@ void test_transfer(int proxy_type, settings_pack const& sett
|
|||
|| st1.state == torrent_status::checking_files);
|
||||
TEST_CHECK(st2.state == torrent_status::downloading
|
||||
|| st2.state == torrent_status::checking_resume_data
|
||||
|| (test_disk_full && !st2.error.empty()));
|
||||
|| (test_disk_full && st2.errc));
|
||||
|
||||
if (!test_disk_full && peer_disconnects >= 2) break;
|
||||
|
||||
|
|
Loading…
Reference in New Issue