Project

General

Profile

Actions

Task #1290

closed

Global io_service and Scheduler

Added by Junxiao Shi over 10 years ago. Updated over 10 years ago.

Status:
Closed
Priority:
Low
Category:
Core
Target version:
Start date:
02/25/2014
Due date:
% Done:

100%

Estimated time:
2.50 h

Description

Create a global instance of io_service and Scheduler.

namespace nfd {
boost::asio::io_service& getGlobalIoService();

namespace scheduler {
struct EventId;
typedef function<void()> Event;
EventId schedule(time::Duration after, Event event);
void cancel(const EventId& eventId);
} // namespace scheduler
using scheduler::EventId; // import to nfd namespace

} // namespace nfd

The global instances can be replaced/cleared/reset during unit testing.


This task is divided to two stages:

Stage 1

  • Create global io_service and Scheduler.
  • nfd::Scheduler class still exists. Its global instance is accessed at nfd::scheduler::getGlobalScheduler().
  • Use the global io_service in main().
  • Forwarder uses the global Scheduler.
  • Unit tests can have their own io_service and Scheduler, if they don't interact with Forwarder.

Stage 2

  • Delete references to io_service and Scheduler in all classes and constructors.
  • Change all scheduler calls to use nfd::scheduler::schedule and nfd::scheduler::cancel.
  • Delete or move away nfd::Scheduler class. Delete nfd::getGlobalScheduler() function.
  • Unit tests also use the global instances, and are provided a way to reset / replace the global io_service and Scheduler.
Actions

Also available in: Atom PDF