* Don't show ETA on finished and stopped torrents.

* Added percentage completed to active unfinished torrents.

* Re-enabled different seeding and leeching priorities.

* Make a temporary container in AvailableList::insert(AddressList*)
when doing std::set_differernce. AvailableList's std::vector would
resize and cause invalidated iterators to be used.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@630 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2006-02-04 19:18:41 +00:00
parent d06ecda46a
commit 68502367ec
17 changed files with 184 additions and 91 deletions
+38 -4
View File
@@ -36,9 +36,12 @@
#include "config.h"
#include <cctype>
#include <cstring>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "lockfile.h"
@@ -47,29 +50,60 @@ namespace utils {
bool
Lockfile::try_lock() {
if (m_path.empty()) {
m_id = "foo";
m_locked = true;
return true;
}
// Just do a simple locking for now that isn't safe for network
// devices.
int fd = ::open(m_path.c_str(), O_RDWR | O_CREAT | O_EXCL);
int fd = ::open(m_path.c_str(), O_RDWR | O_CREAT | O_EXCL, 0444);
if (fd == -1)
return false;
m_id = "foo";
char buf[256];
int pos = ::gethostname(buf, 255);
if (pos == 0) {
::snprintf(buf + std::strlen(buf), 255, ":+%i\n", ::getpid());
::write(fd, buf, std::strlen(buf));
}
::close(fd);
m_locked = true;
return true;
}
bool
Lockfile::unlock() {
m_locked = false;
if (m_path.empty())
return true;
else
return ::unlink(m_path.c_str()) != -1;
}
struct lockfile_valid_char {
bool operator () (char c) {
return !std::isgraph(c);
}
};
std::string
Lockfile::locked_by() const {
int fd = ::open(m_path.c_str(), O_RDONLY);
if (fd < 0)
return "<error>";
char buf[256];
int pos = read(fd, buf, 255);
::close(fd);
return std::string(buf, std::find_if(buf, buf + std::max(pos, 0), lockfile_valid_char()));
}
}
+11 -2
View File
@@ -34,6 +34,12 @@
// Skomakerveien 33
// 3185 Skoppum, NORWAY
// A simple, and not guaranteed atomic, lockfile implementation. It
// saves the hostname and pid in the lock file, which may be accessed
// by Lockfile::locked_by(). If the path is an empty string then no
// lockfile will be created when Lockfile::try_lock() is called, still
// it will set the locked state of the Lockfile instance.
#ifndef RTORRENT_UTILS_LOCKFILE_H
#define RTORRENT_UTILS_LOCKFILE_H
@@ -43,8 +49,9 @@ namespace utils {
class Lockfile {
public:
Lockfile() : m_locked(false) {}
bool is_locked() const { return !m_id.empty(); }
bool is_locked() const { return m_locked; }
// If the path is empty no lock file will be created, although
// is_locked() will return true.
@@ -54,9 +61,11 @@ public:
const std::string& path() const { return m_path; }
void set_path(const std::string& path) { m_path = path; }
std::string locked_by() const;
private:
std::string m_path;
std::string m_id;
bool m_locked;
};
}