Hi,
A while ago I saw:
http://libtorrent.rakshasa.no/ticket/806
and
http://rakshasa.no/pipermail/libtorrent-devel/2007-March/001064.html
I got the idea that (given the somewhat more static number of days per
week) the missing feature of dd:hh:mm:ss could be used as dow:hh:mm:ss,
like:
schedule=wed1,03:11:30:00,07:00:00:00,upload_rate=331
schedule=wed2,03:17:30:00,07:00:00:00,upload_rate=332
schedule=fri,05:15:50:00,07:00:00:00,upload_rate=551
schedule=every_day,20:30:00,24:00:00,upload_rate=999
That might be a bit more useful too, bandwidth usage is probably more
related to day of week than day of month. The modified code below
appears to do what it is supposed to in this regard. Hopefully it does
not do much else. =)
/Olof
uint32_t
CommandScheduler::parse_absolute(const char* str) {
Time result = parse_time(str);
time_t t;
// Do the local time thing.
struct tm local;
switch (result.first) {
case 1:
return result.second;
case 2:
t = cachedTime.tval().tv_sec;
if (localtime_r(&t, &local) == NULL)
throw torrent::input_error("Could not convert unix time to local
time.");
return (result.second + 3600 - 60 * local.tm_min - local.tm_sec) %
3600;
case 3:
t = cachedTime.tval().tv_sec;
if (localtime_r(&t, &local) == NULL)
throw torrent::input_error("Could not convert unix time to local
time.");
return (result.second + 24 * 3600 - 3600 * local.tm_hour - 60 *
local.tm_min - local.tm_sec) % (24 * 3600);
case 4:
t = cachedTime.tval().tv_sec;
if (localtime_r(&t, &local) == NULL)
throw torrent::input_error("Could not convert unix time to local
time.");
return (result.second + 7 * 24 * 3600 - 3600 * 24 * local.tm_wday -
3600 * local.tm_hour - 60 * local.tm_min - local.tm_sec) % (7 * 24 * 3600);
case 0:
default:
throw torrent::input_error("Could not parse interval.");
}
}
CommandScheduler::Time
CommandScheduler::parse_time(const char* str)
{
Time result(0, 0);
int str_parsed[4] = {0,0,0,0};
while (true) {
char* pos;
str_parsed[result.first] = strtol(str, &pos, 10);
if (pos == str || str_parsed[result.first] < 0)
return Time(0, 0);
result.first++;
while (std::isspace(*pos))
++pos;
if (*pos == '\0')
{
if (result.first > 3)
result.second =
str_parsed[3]+(str_parsed[2]+(str_parsed[1]+str_parsed[0]*24)*60)*60;
else
result.second =
str_parsed[2]+(str_parsed[1]+str_parsed[0]*60)*60;
return result;
}
if (*pos != ':' || result.first > 3)
return Time(0, 0);
str = pos + 1;
}
}
}
--
_______________________________________________
Libtorrent-devel mailing list
[email protected]
http://rakshasa.no/mailman/listinfo/libtorrent-devel