From 00e27e4fa47477109fc467d96241a0fabd3c4ad2 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 6 Jul 2013 19:39:16 +0900 Subject: DownloadEngine: Use std::unique_ptr for eventPoll_ --- src/DownloadEngineFactory.cc | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) (limited to 'src/DownloadEngineFactory.cc') diff --git a/src/DownloadEngineFactory.cc b/src/DownloadEngineFactory.cc index 49e9a4bf..0edb3ccc 100644 --- a/src/DownloadEngineFactory.cc +++ b/src/DownloadEngineFactory.cc @@ -84,30 +84,27 @@ namespace aria2 { DownloadEngineFactory::DownloadEngineFactory() {} -std::shared_ptr -DownloadEngineFactory::newDownloadEngine -(Option* op, std::vector > requestGroups) +namespace { +std::unique_ptr createEventPoll(Option* op) { - const size_t MAX_CONCURRENT_DOWNLOADS = - op->getAsInt(PREF_MAX_CONCURRENT_DOWNLOADS); - std::shared_ptr eventPoll; const std::string& pollMethod = op->get(PREF_EVENT_POLL); #ifdef HAVE_LIBUV if (pollMethod == V_LIBUV) { - std::shared_ptr ep(new LibuvEventPoll()); - if (!ep->good()) { + auto ep = make_unique(); + if(ep->good()) { + return std::move(ep); + } else { throw DL_ABORT_EX("Initializing LibuvEventPoll failed." " Try --event-poll=select"); } - eventPoll = ep; } else #endif // HAVE_LIBUV #ifdef HAVE_EPOLL if(pollMethod == V_EPOLL) { - std::shared_ptr ep(new EpollEventPoll()); + auto ep = make_unique(); if(ep->good()) { - eventPoll = ep; + return std::move(ep); } else { throw DL_ABORT_EX("Initializing EpollEventPoll failed." " Try --event-poll=select"); @@ -116,9 +113,9 @@ DownloadEngineFactory::newDownloadEngine #endif // HAVE_EPLL #ifdef HAVE_KQUEUE if(pollMethod == V_KQUEUE) { - std::shared_ptr kp(new KqueueEventPoll()); + auto kp = make_unique(); if(kp->good()) { - eventPoll = kp; + return std::move(kp); } else { throw DL_ABORT_EX("Initializing KqueueEventPoll failed." " Try --event-poll=select"); @@ -127,9 +124,9 @@ DownloadEngineFactory::newDownloadEngine #endif // HAVE_KQUEUE #ifdef HAVE_PORT_ASSOCIATE if(pollMethod == V_PORT) { - std::shared_ptr pp(new PortEventPoll()); + auto pp = make_unique(); if(pp->good()) { - eventPoll = pp; + return std::move(pp); } else { throw DL_ABORT_EX("Initializing PortEventPoll failed." " Try --event-poll=select"); @@ -138,15 +135,24 @@ DownloadEngineFactory::newDownloadEngine #endif // HAVE_PORT_ASSOCIATE #ifdef HAVE_POLL if(pollMethod == V_POLL) { - eventPoll.reset(new PollEventPoll()); + return make_unique(); } else #endif // HAVE_POLL if(pollMethod == V_SELECT) { - eventPoll.reset(new SelectEventPoll()); + return make_unique(); } else { - abort(); + assert(0); } - std::shared_ptr e(new DownloadEngine(eventPoll)); +} +} // namespace + +std::shared_ptr +DownloadEngineFactory::newDownloadEngine +(Option* op, std::vector > requestGroups) +{ + const size_t MAX_CONCURRENT_DOWNLOADS = + op->getAsInt(PREF_MAX_CONCURRENT_DOWNLOADS); + auto e = std::make_shared(createEventPoll(op)); e->setOption(op); { auto requestGroupMan = make_unique -- cgit