diff --git a/doc/rtorrent.1 b/doc/rtorrent.1
index 6bc74593..c6964210 100644
--- a/doc/rtorrent.1
+++ b/doc/rtorrent.1
@@ -3,7 +3,7 @@
.\"
.\" Please send any bug reports, improvements, comments, patches,
.\" etc. to Steve Cheng .
-.TH "RTORRENT" "1" "21 October 2006" "BitTorrent client for ncurses" ""
+.TH "RTORRENT" "1" "25 October 2006" "BitTorrent client for ncurses" ""
.SH NAME
rtorrent \- a BitTorrent client for ncurses
@@ -425,9 +425,12 @@ Controls if a lock file is created in the session directory on startup.
Save the session files for all downloads.
.TP
\fBtos = \fIdefault|lowdelay|throughput|reliability|mincost\fB\fR
+.TP
+\fBtos = \fIhex\fB\fR
Change the TOS of peer connections, by default set to
\fBthroughput\fR\&. If the option is set to
-\fBdefault\fR then the system default TOS is used.
+\fBdefault\fR then the system default TOS is used. A
+hex value may be used for non-standard settings.
.TP
\fBhandshake_log = \fIyes\fB\fR
Enable logging of the peer handshake. This generates a large number of
diff --git a/doc/rtorrent.1.xml b/doc/rtorrent.1.xml
index 5a07e25b..f987a17b 100644
--- a/doc/rtorrent.1.xml
+++ b/doc/rtorrent.1.xml
@@ -897,12 +897,12 @@ Save the session files for all downloads.
tos = default|lowdelay|throughput|reliability|mincost
+ tos = hex
-
Change the TOS of peer connections, by default set to
throughput. If the option is set to
-default then the system default TOS is used.
-
+default then the system default TOS is used. A
+hex value may be used for non-standard settings.
diff --git a/src/option_handler_rules.cc b/src/option_handler_rules.cc
index bd469091..f91ff5f9 100644
--- a/src/option_handler_rules.cc
+++ b/src/option_handler_rules.cc
@@ -279,25 +279,28 @@ apply_enable_trackers(Control* m, __UNUSED const std::string& arg) {
void
apply_tos(const std::string& arg) {
+ utils::Variable::value_type value;
torrent::ConnectionManager* cm = torrent::connection_manager();
if (arg == "default")
- cm->set_priority(torrent::ConnectionManager::iptos_default);
+ value = torrent::ConnectionManager::iptos_default;
else if (arg == "lowdelay")
- cm->set_priority(torrent::ConnectionManager::iptos_lowdelay);
+ value = torrent::ConnectionManager::iptos_lowdelay;
else if (arg == "throughput")
- cm->set_priority(torrent::ConnectionManager::iptos_throughput);
+ value = torrent::ConnectionManager::iptos_throughput;
else if (arg == "reliability")
- cm->set_priority(torrent::ConnectionManager::iptos_reliability);
+ value = torrent::ConnectionManager::iptos_reliability;
else if (arg == "mincost")
- cm->set_priority(torrent::ConnectionManager::iptos_mincost);
+ value = torrent::ConnectionManager::iptos_mincost;
- else
+ else if (!utils::Variable::string_to_value_unit_nothrow(arg.c_str(), &value, 16, 0))
throw torrent::input_error("Invalid TOS identifier.");
+
+ cm->set_priority(value);
}
void
diff --git a/src/utils/variable.cc b/src/utils/variable.cc
index 161e352e..42e8c260 100644
--- a/src/utils/variable.cc
+++ b/src/utils/variable.cc
@@ -94,4 +94,15 @@ Variable::string_to_value_unit(const char* pos, value_type* value, int base, int
return last;
}
+bool
+Variable::string_to_value_unit_nothrow(const char* pos, value_type* value, int base, int unit) {
+ try {
+ string_to_value_unit(pos, value, base, unit);
+
+ return true;
+ } catch (const torrent::input_error& e) {
+ return false;
+ }
+}
+
}
diff --git a/src/utils/variable.h b/src/utils/variable.h
index e2130bc1..b2a4048e 100644
--- a/src/utils/variable.h
+++ b/src/utils/variable.h
@@ -56,6 +56,7 @@ public:
virtual void set(const torrent::Object& arg) = 0;
static const char* string_to_value_unit(const char* pos, value_type* value, int base, int unit);
+ static bool string_to_value_unit_nothrow(const char* pos, value_type* value, int base, int unit);
protected:
Variable(const Variable&);