summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/DownloadEngine.cc17
-rw-r--r--src/DownloadEngine.h2
-rw-r--r--src/DownloadEngineFactory.cc3
-rw-r--r--src/EvictSocketPoolCommand.cc64
-rw-r--r--src/EvictSocketPoolCommand.h53
-rw-r--r--src/Makefile.am3
6 files changed, 134 insertions, 8 deletions
diff --git a/src/DownloadEngine.cc b/src/DownloadEngine.cc
index 522c1b2e..3bc7b18e 100644
--- a/src/DownloadEngine.cc
+++ b/src/DownloadEngine.cc
@@ -311,22 +311,25 @@ void DownloadEngine::poolSocket(const std::string& key,
A2_LOG_INFO(fmt("Pool socket for %s", key.c_str()));
std::multimap<std::string, SocketPoolEntry>::value_type p(key, entry);
socketPool_.insert(p);
+}
- if(lastSocketPoolScan_.difference(global::wallclock()) < 1_min) {
+void DownloadEngine::evictSocketPool()
+{
+ if (socketPool_.empty()) {
return;
}
+
std::multimap<std::string, SocketPoolEntry> newPool;
A2_LOG_DEBUG("Scaning SocketPool and erasing timed out entry.");
- lastSocketPoolScan_ = global::wallclock();
- for(auto & elem : socketPool_) {
- if(!elem.second.isTimeout()) {
+ for (auto& elem : socketPool_) {
+ if (!elem.second.isTimeout()) {
newPool.insert(elem);
}
}
A2_LOG_DEBUG(fmt("%lu entries removed.",
- static_cast<unsigned long>
- (socketPool_.size()-newPool.size())));
- socketPool_ = newPool;
+ static_cast<unsigned long>
+ (socketPool_.size() - newPool.size())));
+ socketPool_ = std::move(newPool);
}
namespace {
diff --git a/src/DownloadEngine.h b/src/DownloadEngine.h
index 749092a2..a6709f5a 100644
--- a/src/DownloadEngine.h
+++ b/src/DownloadEngine.h
@@ -311,6 +311,8 @@ public:
uint16_t port,
const std::string& username);
+ void evictSocketPool();
+
const std::unique_ptr<CookieStorage>& getCookieStorage() const;
#ifdef ENABLE_BITTORRENT
diff --git a/src/DownloadEngineFactory.cc b/src/DownloadEngineFactory.cc
index 6f07c2f6..8bc96e19 100644
--- a/src/DownloadEngineFactory.cc
+++ b/src/DownloadEngineFactory.cc
@@ -57,6 +57,7 @@
#include "a2io.h"
#include "DownloadContext.h"
#include "array_fun.h"
+#include "EvictSocketPoolCommand.h"
#ifdef HAVE_LIBUV
# include "LibuvEventPoll.h"
#endif // HAVE_LIBUV
@@ -164,6 +165,8 @@ DownloadEngineFactory::newDownloadEngine
e->addRoutineCommand(make_unique<CheckIntegrityDispatcherCommand>
(e->newCUID(), e->getCheckIntegrityMan().get(),
e.get()));
+ e->addRoutineCommand(make_unique<EvictSocketPoolCommand>
+ (e->newCUID(), e.get(), 30_s));
if(op->getAsInt(PREF_AUTO_SAVE_INTERVAL) > 0) {
e->addRoutineCommand(make_unique<AutoSaveCommand>(
diff --git a/src/EvictSocketPoolCommand.cc b/src/EvictSocketPoolCommand.cc
new file mode 100644
index 00000000..59af6843
--- /dev/null
+++ b/src/EvictSocketPoolCommand.cc
@@ -0,0 +1,64 @@
+/* <!-- copyright */
+/*
+ * aria2 - The high speed download utility
+ *
+ * Copyright (C) 2015 Tatsuhiro Tsujikawa
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * In addition, as a special exception, the copyright holders give
+ * permission to link the code of portions of this program with the
+ * OpenSSL library under certain conditions as described in each
+ * individual source file, and distribute linked combinations
+ * including the two.
+ * You must obey the GNU General Public License in all respects
+ * for all of the code used other than OpenSSL. If you modify
+ * file(s) with this exception, you may extend this exception to your
+ * version of the file(s), but you are not obligated to do so. If you
+ * do not wish to do so, delete this exception statement from your
+ * version. If you delete this exception statement from all source
+ * files in the program, then also delete it here.
+ */
+/* copyright --> */
+#include "EvictSocketPoolCommand.h"
+#include "RequestGroupMan.h"
+#include "DownloadEngine.h"
+
+namespace aria2 {
+
+EvictSocketPoolCommand::EvictSocketPoolCommand(cuid_t cuid, DownloadEngine* e,
+ std::chrono::seconds interval)
+ : TimeBasedCommand(cuid, e, std::move(interval), true)
+{
+}
+
+EvictSocketPoolCommand::~EvictSocketPoolCommand()
+{
+}
+
+void EvictSocketPoolCommand::preProcess()
+{
+ if(getDownloadEngine()->getRequestGroupMan()->downloadFinished() ||
+ getDownloadEngine()->isHaltRequested()) {
+ enableExit();
+ }
+}
+
+void EvictSocketPoolCommand::process()
+{
+ getDownloadEngine()->evictSocketPool();
+}
+
+} // namespace aria2
diff --git a/src/EvictSocketPoolCommand.h b/src/EvictSocketPoolCommand.h
new file mode 100644
index 00000000..c118a393
--- /dev/null
+++ b/src/EvictSocketPoolCommand.h
@@ -0,0 +1,53 @@
+/* <!-- copyright */
+/*
+ * aria2 - The high speed download utility
+ *
+ * Copyright (C) 2015 Tatsuhiro Tsujikawa
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * In addition, as a special exception, the copyright holders give
+ * permission to link the code of portions of this program with the
+ * OpenSSL library under certain conditions as described in each
+ * individual source file, and distribute linked combinations
+ * including the two.
+ * You must obey the GNU General Public License in all respects
+ * for all of the code used other than OpenSSL. If you modify
+ * file(s) with this exception, you may extend this exception to your
+ * version of the file(s), but you are not obligated to do so. If you
+ * do not wish to do so, delete this exception statement from your
+ * version. If you delete this exception statement from all source
+ * files in the program, then also delete it here.
+ */
+/* copyright --> */
+#ifndef D_EVICT_SOCKET_POOL_COMMAND_H
+#define D_EVICT_SOCKET_POOL_COMMAND_H
+
+#include "TimeBasedCommand.h"
+
+namespace aria2 {
+
+class EvictSocketPoolCommand : public TimeBasedCommand {
+public:
+ EvictSocketPoolCommand(cuid_t cuid, DownloadEngine* e,
+ std::chrono::seconds interval);
+ virtual ~EvictSocketPoolCommand();
+ virtual void preProcess() CXX11_OVERRIDE;
+ virtual void process() CXX11_OVERRIDE;
+};
+
+} // namespace aria2
+
+#endif // D_EVICT_SOCKET_POOL_COMMAND_H
diff --git a/src/Makefile.am b/src/Makefile.am
index 6850a778..7f253c56 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -268,7 +268,8 @@ SRCS = \
WrDiskCacheEntry.cc WrDiskCacheEntry.h\
XmlRpcRequestParserController.cc XmlRpcRequestParserController.h\
OpenedFileCounter.cc OpenedFileCounter.h \
- SHA1IOFile.cc SHA1IOFile.h
+ SHA1IOFile.cc SHA1IOFile.h \
+ EvictSocketPoolCommand.cc EvictSocketPoolCommand.h
if ANDROID
SRCS += android/android.c