[pan2/bug_102402] first draft
- From: Heinrich MÃller <henmull src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pan2/bug_102402] first draft
- Date: Sat, 23 Jun 2012 10:42:58 +0000 (UTC)
commit d49a719970dca1a201128b392eb38d809c3a2443
Author: Heinrich MÃller <heinrich mueller82 gmail com>
Date: Fri Jun 22 15:12:36 2012 +0200
first draft
pan/data-impl/data-impl.cc | 65 +++++++++++++++++++++++++++++++++++++-
pan/data-impl/data-impl.h | 18 +++++++++-
pan/data-impl/server.cc | 15 ++++++++-
pan/data/data.h | 3 +-
pan/data/server-info.h | 3 ++
pan/gui/pan.cc | 1 +
pan/tasks/nntp-pool.cc | 19 +++++++++++-
pan/tasks/nntp-pool.h | 29 +++++++++--------
pan/tasks/queue.cc | 6 ++--
pan/tasks/socket-impl-main.cc | 1 +
pan/tasks/socket-impl-openssl.h | 1 +
pan/tasks/socket.cc | 9 +++++-
pan/tasks/socket.h | 19 +++++++++++-
13 files changed, 163 insertions(+), 26 deletions(-)
---
diff --git a/pan/data-impl/data-impl.cc b/pan/data-impl/data-impl.cc
index e3410e9..f6a5375 100644
--- a/pan/data-impl/data-impl.cc
+++ b/pan/data-impl/data-impl.cc
@@ -77,7 +77,9 @@ DataImpl :: DataImpl (const StringView& cache_ext, Prefs& prefs, bool unit_test,
_prefs (prefs),
_descriptions_loaded (false),
newsrc_autosave_id (0),
- newsrc_autosave_timeout (0)
+ newsrc_autosave_timeout (0),
+ xfer_autosave_id (0),
+ xfer_autosave_timeout (0)
{
rebuild_backend ();
@@ -100,6 +102,7 @@ DataImpl :: rebuild_backend ()
load_server_properties (*_data_io);
load_newsrc_files (*_data_io);
+ load_xfer_files (*_data_io);
load_group_xovers (*_data_io);
load_group_permissions (*_data_io);
@@ -111,6 +114,64 @@ DataImpl :: rebuild_backend ()
}
}
+namespace {
+ inline std::string build_path(const std::string &base)
+ {
+ const char *fn = base.c_str();
+ if (g_path_is_absolute(fn))
+ return base;
+ const char *ph = file::get_pan_home().c_str();
+ char *temp = g_build_filename(ph, fn, NULL);
+ std::string out(temp);
+ g_free(temp);
+ return out;
+ }
+}
+
+void
+DataImpl :: load_xfer_files (const DataIO& data_io)
+{
+ const std::string filename = build_path ("server_xfer");
+ if (file::file_exists (filename.c_str())) {
+ LineReader * in (data_io.read_file (filename));
+
+ StringView line;
+ while (!in->fail() && in->getline (line))
+ {
+ StringView server;
+ line.pop_token(server);
+ StringView val;
+ line.pop_token (val);
+ unsigned long bytes (atoi(val.str));
+ }
+
+ delete in;
+ }
+
+}
+
+void
+DataImpl :: save_xfer_files (DataIO& data_io) const
+{
+ if (!in_xfer_cb && xfer_autosave_id)
+ g_source_remove( xfer_autosave_id );
+
+ if (_unit_test)
+ return;
+
+ const std::string filename = build_path ("server_xfer");
+ std::ostream& out (*data_io.write_file (filename));
+
+ foreach_const (servers_t, _servers, sit)
+ {
+ const Quark& server (sit->first);
+ const Server& s (sit->second);
+ out << server<<" "<<s.xfer<<"\n";
+ }
+ data_io.write_done (&out);
+
+}
+
DataImpl :: ~DataImpl ()
{
save_state ();
@@ -125,6 +186,7 @@ DataImpl :: save_state ()
debug ("data-impl dtor saving xov, newsrc...");
save_group_xovers (*_data_io);
save_newsrc_files (*_data_io);
+ save_xfer_files (*_data_io);
}
}
@@ -132,7 +194,6 @@ DataImpl :: save_state ()
GnomeKeyringResult
DataImpl :: password_encrypt (const PasswordData& pw)
{
-// g_return_val_if_fail (pw, GNOME_KEYRING_RESULT_NO_KEYRING_DAEMON);
return (
gnome_keyring_store_password_sync (
diff --git a/pan/data-impl/data-impl.h b/pan/data-impl/data-impl.h
index 9f8faa6..ec0809a 100644
--- a/pan/data-impl/data-impl.h
+++ b/pan/data-impl/data-impl.h
@@ -157,6 +157,8 @@ namespace pan
virtual void set_server_article_expiration_age (const Quark & server,
int days);
+ virtual void increment_server_xfer_count(const Quark& server, unsigned long bytes) ;
+
virtual void save_server_info (const Quark& server);
public: // accessors
@@ -287,11 +289,13 @@ namespace pan
void load_group_permissions (const DataIO&);
void save_group_permissions (DataIO&) const;
- std::string get_newsrc_filename (const Quark& server) const;
void load_newsrc (const Quark& server, LineReader*, alpha_groups_t&, alpha_groups_t&);
void load_newsrc_files (const DataIO&);
void save_newsrc_files (DataIO&) const;
+ void load_xfer_files (const DataIO&);
+ void save_xfer_files (DataIO&) const;
+
public: // mutators
virtual void add_groups (const Quark & server,
@@ -649,7 +653,6 @@ namespace pan
const Quark & server,
const uint64_t low);
-
/**
*** TaskArchive
**/
@@ -680,6 +683,17 @@ namespace pan
newsrc_autosave_id = 0;
}
+ guint xfer_autosave_id;
+ guint xfer_autosave_timeout;
+ bool in_xfer_cb;
+ void set_xfer_autosave_timeout(guint seconds)
+ {xfer_autosave_timeout = seconds;}
+ void save_xfer_files()
+ {
+ save_xfer_files(*_data_io);
+ xfer_autosave_id = 0;
+ }
+
};
}
diff --git a/pan/data-impl/server.cc b/pan/data-impl/server.cc
index 40f27c0..89a93c7 100644
--- a/pan/data-impl/server.cc
+++ b/pan/data-impl/server.cc
@@ -211,10 +211,21 @@ DataImpl :: set_server_cert (const Quark & server,
}
void
-DataImpl :: save_server_info (const Quark& server)
+DataImpl :: increment_server_xfer_count(const Quark& server, unsigned long bytes)
{
Server * s (find_server (server));
assert (s);
+// mut.lock()
+ s->xfer += bytes;
+// mut.unlock();
+}
+
+void
+DataImpl :: save_server_info (const Quark& server)
+{
+// std::cerr<<"find "<<server<<"\n";
+// Server * s (find_server (server));
+// assert (s);
save_server_properties (*_data_io, _prefs);
}
@@ -376,7 +387,6 @@ DataImpl :: get_server_article_expiration_age (const Quark & server) const
}
-
/***
****
***/
@@ -476,6 +486,7 @@ DataImpl :: load_server_properties (const DataIO& source)
s.max_connections = to_int (kv["connection-limit"], 2);
s.article_expiration_age = to_int(kv["expire-articles-n-days-old"], 31);
s.rank = to_int(kv["rank"], 1);
+ s.xfer = to_int(kv["rank"], 0);
int ssl(to_int(kv["use-ssl"], 0));
s.ssl_support = ssl;
s.cert = kv["cert"];
diff --git a/pan/data/data.h b/pan/data/data.h
index e76a26a..007d41b 100644
--- a/pan/data/data.h
+++ b/pan/data/data.h
@@ -199,9 +199,10 @@ namespace pan
typedef sorted_vector<Quark,true,AlphabeticalQuarkOrdering> groups_t;
groups_t groups;
gchar* gkr_pw;
+ unsigned long xfer;
Server(): port(STD_NNTP_PORT), article_expiration_age(31), max_connections(2),
- rank(1), ssl_support(0), trust(0), gkr_pw(NULL) {}
+ rank(1), ssl_support(0), trust(0), gkr_pw(NULL), xfer(0) {}
};
protected:
diff --git a/pan/data/server-info.h b/pan/data/server-info.h
index 7f4f6a9..ebb5d31 100644
--- a/pan/data/server-info.h
+++ b/pan/data/server-info.h
@@ -72,6 +72,8 @@ namespace pan
virtual void save_server_info (const Quark& server) = 0;
+ virtual void increment_server_xfer_count(const Quark& server, unsigned long bytes) = 0;
+
public: // accessors
virtual bool get_server_auth (const Quark & servername,
@@ -98,6 +100,7 @@ namespace pan
virtual int get_server_article_expiration_age (const Quark & server) const = 0;
virtual bool find_server_by_hn (const std::string& server, Quark& setme) const = 0;
+
};
}
diff --git a/pan/gui/pan.cc b/pan/gui/pan.cc
index 0c39e64..c99b3fe 100644
--- a/pan/gui/pan.cc
+++ b/pan/gui/pan.cc
@@ -1065,6 +1065,7 @@ main (int argc, char *argv[])
gnome_keyring_memory_free(s->gkr_pw);
}
}
+// data.save_server_info(Quark());
#endif
}
diff --git a/pan/tasks/nntp-pool.cc b/pan/tasks/nntp-pool.cc
index 17a7c09..d856b7c 100644
--- a/pan/tasks/nntp-pool.cc
+++ b/pan/tasks/nntp-pool.cc
@@ -168,11 +168,28 @@ NNTP_Pool :: check_in (NNTP * nntp, Health health)
***/
void
+NNTP_Pool :: on_socket_data_transferred (unsigned long bytes, Socket* sock)
+{
+ Quark server;
+ std::string setme;
+ sock->get_host(setme);
+ _server_info.find_server_by_hn(setme, server);
+ _server_info.increment_server_xfer_count(server, bytes);
+}
+
+/***
+****
+***/
+
+void
NNTP_Pool :: on_socket_created (const StringView & host,
int port UNUSED,
bool ok,
Socket * socket)
{
+
+ socket->add_byte_listener(this);
+
std::string user;
gchar* pass(NULL);
ok = ok && _server_info.get_server_auth (_server, user, pass, _prefs.get_flag("use-gnome-keyring", false));
@@ -201,7 +218,6 @@ NNTP_Pool :: on_socket_created (const StringView & host,
}
}
-
void
NNTP_Pool :: on_nntp_done (NNTP* nntp, Health health, const StringView& response)
{
@@ -301,6 +317,7 @@ NNTP_Pool :: request_nntp (WorkerPool& threadpool)
{
++_pending_connections;
const bool ssl(_server_info.get_server_ssl_support(_server));
+ // creates socket and registers listener for byte count
_socket_creator->create_socket (_server_info, address, port, threadpool, this, ssl);
}
}
diff --git a/pan/tasks/nntp-pool.h b/pan/tasks/nntp-pool.h
index 7399b72..e045b20 100644
--- a/pan/tasks/nntp-pool.h
+++ b/pan/tasks/nntp-pool.h
@@ -44,6 +44,7 @@ struct WorkerPool;
class NNTP_Pool: public NNTP::Source,
private NNTP::Listener,
private Socket::Creator::Listener,
+ private Socket::ByteListener,
private CertStore::Listener {
public:
@@ -81,21 +82,23 @@ public:
}
void request_nntp(WorkerPool&);
-private:
- // NNTP::Listener
- virtual void on_nntp_done(NNTP*, Health, const StringView&);
+ private:
+ // NNTP::Listener
+ virtual void on_nntp_done(NNTP*, Health, const StringView&);
+
+ private:
+ // Socket::Creator::Listener
+ virtual void on_socket_created(const StringView& host, int port, bool ok, Socket*);
+ virtual void on_socket_shutdown(const StringView& host, int port, Socket*) {}
+
+ private:
+ virtual void on_socket_data_transferred (unsigned long bytes, Socket* sock) ;
-private:
- // Socket::Creator::Listener
- virtual void on_socket_created(const StringView& host, int port, bool ok,
- Socket*);
- virtual void on_socket_shutdown(const StringView& host, int port, Socket*) {
- }
#ifdef HAVE_GNUTLS
-private:
- // CertStore::Listener
- virtual void on_verify_cert_failed(gnutls_x509_crt_t, std::string, int);
- virtual void on_valid_cert_added(gnutls_x509_crt_t, std::string);
+ private:
+ // CertStore::Listener
+ virtual void on_verify_cert_failed(gnutls_x509_crt_t, std::string, int);
+ virtual void on_valid_cert_added(gnutls_x509_crt_t, std::string);
#endif
private:
diff --git a/pan/tasks/queue.cc b/pan/tasks/queue.cc
index cab893f..f517fcf 100644
--- a/pan/tasks/queue.cc
+++ b/pan/tasks/queue.cc
@@ -904,7 +904,7 @@ Queue :: get_full_connection_counts (std::vector<ServerConnectionCounts>& setme)
it->second->get_counts (counts.active, counts.idle, counts.connecting, unused);
foreach_const (nntp_to_task_t, _nntp_to_task, nit)
if (nit->first->_server == counts.server_id)
- counts.KiBps += nit->first->_socket->get_speed_KiBps ();
+ counts.KiBps += nit->first->_socket->get_speed_KiBps();
}
}
@@ -913,7 +913,7 @@ Queue :: get_speed_KiBps () const
{
double KiBps (0.0);
foreach_const (nntp_to_task_t, _nntp_to_task, it)
- KiBps += it->first->_socket->get_speed_KiBps ();
+ KiBps += it->first->_socket->get_speed_KiBps();
return KiBps;
}
@@ -927,7 +927,7 @@ Queue :: get_task_speed_KiBps (const Task * task,
foreach_const (nntp_to_task_t, _nntp_to_task, it) {
if (it->second==task) {
++connections;
- KiBps += it->first->_socket->get_speed_KiBps ();
+ KiBps += it->first->_socket->get_speed_KiBps();
}
}
diff --git a/pan/tasks/socket-impl-main.cc b/pan/tasks/socket-impl-main.cc
index d91eff2..4f6c60b 100644
--- a/pan/tasks/socket-impl-main.cc
+++ b/pan/tasks/socket-impl-main.cc
@@ -152,6 +152,7 @@ SocketCreator :: create_socket (ServerInfo& info,
ThreadWorker * w = new ThreadWorker (info, server, host, port, listener);
#endif
threadpool.push_work (w, w, true);
+
}
#ifdef HAVE_GNUTLS
diff --git a/pan/tasks/socket-impl-openssl.h b/pan/tasks/socket-impl-openssl.h
index b3199ba..1f3b046 100644
--- a/pan/tasks/socket-impl-openssl.h
+++ b/pan/tasks/socket-impl-openssl.h
@@ -80,6 +80,7 @@ namespace pan
bool _rehandshake;
Quark _server;
bool _done;
+ long long _bytes;
private:
enum WatchMode { READ_NOW, WRITE_NOW, IGNORE_NOW };
diff --git a/pan/tasks/socket.cc b/pan/tasks/socket.cc
index 2cd12db..ff317b9 100644
--- a/pan/tasks/socket.cc
+++ b/pan/tasks/socket.cc
@@ -50,8 +50,14 @@ Socket :: is_abort_set () const
return _abort_flag;
}
+void
+Socket :: fire_socket_data_transferred (unsigned long bytes) {
+ for (listeners_cit it(_byte_listeners.begin()), end(_byte_listeners.end()); it!=end; )
+ (*it++)->on_socket_data_transferred (bytes, this);
+}
+
double
-Socket :: get_speed_KiBps () const
+Socket :: get_speed_KiBps ()
{
const time_t now (time(0));
@@ -60,6 +66,7 @@ Socket :: get_speed_KiBps () const
const int delta = now - _time_of_last_check;
const double current_speed = (_bytes_since_last_check/1024.0) / delta;
_time_of_last_check = now;
+ fire_socket_data_transferred(_bytes_since_last_check);
_bytes_since_last_check = 0;
_speed_KiBps = (std::fabs(_speed_KiBps)<0.0001)
diff --git a/pan/tasks/socket.h b/pan/tasks/socket.h
index 6947229..73ed093 100644
--- a/pan/tasks/socket.h
+++ b/pan/tasks/socket.h
@@ -22,6 +22,7 @@
#include <string>
#include <config.h>
+#include <set>
#ifdef HAVE_GNUTLS
#include <gnutls/gnutls.h>
@@ -42,6 +43,22 @@ namespace pan
class Socket
{
public:
+ struct ByteListener {
+ virtual ~ByteListener () {}
+ virtual void on_socket_data_transferred (unsigned long, Socket*) = 0;
+ };
+ virtual void add_byte_listener (ByteListener * l) { if (!l) return; _byte_listeners.insert (l); }
+ virtual void remove_byte_listener (ByteListener * l) { if (!l) return; _byte_listeners.erase (l); }
+
+ private:
+
+ void fire_socket_data_transferred (unsigned long bytes) ;
+
+ typedef std::set<ByteListener*> listeners_t;
+ typedef Socket::listeners_t::const_iterator listeners_cit;
+ listeners_t _byte_listeners;
+
+ public:
Socket ();
virtual ~Socket () {}
@@ -60,7 +77,7 @@ namespace pan
public:
void write_command_va (Listener*, const char * fmt, ...);
- double get_speed_KiBps () const;
+ double get_speed_KiBps () ;
void reset_speed_counter ();
void set_abort_flag (bool b);
bool is_abort_set () const;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]