face: Convert to use the global IO service by all ChannelFactories

Change-Id: Ibd8d5cea142171b5700d8920eb3eedc084bbd588
diff --git a/daemon/face/channel-factory.hpp b/daemon/face/channel-factory.hpp
index 184703a..566063b 100644
--- a/daemon/face/channel-factory.hpp
+++ b/daemon/face/channel-factory.hpp
@@ -11,16 +11,9 @@
 
 namespace nfd {
 
-/**
- * \brief Base class for all channel factories
- */
-template<class E, class C>
 class ChannelFactory
 {
 public:
-  typedef E Endpoint;
-  typedef C Channel;
-  
   /**
    * \brief Base class for all exceptions thrown by channel factories
    */
@@ -29,9 +22,6 @@
     Error(const std::string& what) : std::runtime_error(what) {}
   };
 
-protected:
-  typedef std::map< Endpoint, shared_ptr<Channel> > ChannelMap;
-  ChannelMap m_channels;  
 };
 
 } // namespace nfd
diff --git a/daemon/face/ethernet-channel-factory.hpp b/daemon/face/ethernet-channel-factory.hpp
index 4f655bd..a9094af 100644
--- a/daemon/face/ethernet-channel-factory.hpp
+++ b/daemon/face/ethernet-channel-factory.hpp
@@ -8,18 +8,19 @@
 #define NFD_FACE_ETHERNET_CHANNEL_FACTORY_HPP
 
 #include "ethernet-face.hpp"
+#include "channel-factory.hpp"
 
 namespace nfd {
 
-class EthernetChannelFactory
+class EthernetChannelFactory : public ChannelFactory
 {
 public:
   /**
    * \brief Exception of EthernetChannelFactory
    */
-  struct Error : public std::runtime_error
+  struct Error : public ChannelFactory::Error
   {
-    Error(const std::string& what) : std::runtime_error(what) {}
+    Error(const std::string& what) : ChannelFactory::Error(what) {}
   };
 
   /**
diff --git a/daemon/face/tcp-channel-factory.cpp b/daemon/face/tcp-channel-factory.cpp
index be3a9d4..3a75183 100644
--- a/daemon/face/tcp-channel-factory.cpp
+++ b/daemon/face/tcp-channel-factory.cpp
@@ -5,14 +5,10 @@
  */
 
 #include "tcp-channel-factory.hpp"
+#include "core/global-io.hpp"
 
 namespace nfd {
 
-TcpChannelFactory::TcpChannelFactory(boost::asio::io_service& ioService)
-  : m_ioService(ioService)
-{
-}
-
 shared_ptr<TcpChannel>
 TcpChannelFactory::create(const tcp::Endpoint& endpoint)
 {
@@ -20,7 +16,7 @@
   if(static_cast<bool>(channel))
     return channel;
 
-  channel = make_shared<TcpChannel>(boost::ref(m_ioService), boost::cref(endpoint));
+  channel = make_shared<TcpChannel>(boost::ref(getGlobalIoService()), boost::cref(endpoint));
   m_channels[endpoint] = channel;
   return channel;
 }
@@ -29,11 +25,9 @@
 TcpChannelFactory::create(const std::string& localHost, const std::string& localPort)
 {
   using boost::asio::ip::tcp;
-  
+
   tcp::resolver::query query(localHost, localPort);
-  // shared_ptr<tcp::resolver> resolver =
-  //   make_shared<tcp::resolver>(boost::ref(m_ioService));
-  tcp::resolver resolver(m_ioService);
+  tcp::resolver resolver(getGlobalIoService());
 
   tcp::resolver::iterator end;
   tcp::resolver::iterator i = resolver.resolve(query);
diff --git a/daemon/face/tcp-channel-factory.hpp b/daemon/face/tcp-channel-factory.hpp
index 171c24f..c87cdf4 100644
--- a/daemon/face/tcp-channel-factory.hpp
+++ b/daemon/face/tcp-channel-factory.hpp
@@ -12,23 +12,17 @@
 
 namespace nfd {
 
-class TcpChannelFactory : public ChannelFactory<tcp::Endpoint, TcpChannel>
+class TcpChannelFactory : public ChannelFactory
 {
 public:
   /**
    * \brief Exception of TcpChannelFactory
    */
-  struct Error : public ChannelFactory<tcp::Endpoint, TcpChannel>::Error
+  struct Error : public ChannelFactory::Error
   {
-    Error(const std::string& what)
-      : ChannelFactory<tcp::Endpoint, TcpChannel>::Error(what)
-    {
-    }
+    Error(const std::string& what) : ChannelFactory::Error(what) {}
   };
 
-  explicit
-  TcpChannelFactory(boost::asio::io_service& ioService);
-
   /**
    * \brief Create TCP-based channel using tcp::Endpoint
    *
@@ -67,7 +61,7 @@
    * \brief Look up TcpChannel using specified local endpoint
    *
    * \returns shared pointer to the existing TcpChannel object
-   *          or empty shared pointer when such channel does not exist 
+   *          or empty shared pointer when such channel does not exist
    *
    * \throws never
    */
@@ -75,7 +69,8 @@
   find(const tcp::Endpoint& localEndpoint);
 
 private:
-  boost::asio::io_service& m_ioService;
+  typedef std::map< tcp::Endpoint, shared_ptr<TcpChannel> > ChannelMap;
+  ChannelMap m_channels;
 };
 
 } // namespace nfd
diff --git a/daemon/face/unix-stream-channel-factory.cpp b/daemon/face/unix-stream-channel-factory.cpp
index ededecd..040c1e2 100644
--- a/daemon/face/unix-stream-channel-factory.cpp
+++ b/daemon/face/unix-stream-channel-factory.cpp
@@ -5,13 +5,13 @@
  */
 
 #include "unix-stream-channel-factory.hpp"
+#include "core/global-io.hpp"
 
 #include <boost/filesystem.hpp> // for canonical()
 
 namespace nfd {
 
-UnixStreamChannelFactory::UnixStreamChannelFactory(boost::asio::io_service& ioService)
-  : m_ioService(ioService)
+UnixStreamChannelFactory::UnixStreamChannelFactory()
 {
 }
 
@@ -26,7 +26,7 @@
   if (channel)
     return channel;
 
-  channel = make_shared<UnixStreamChannel>(boost::ref(m_ioService),
+  channel = make_shared<UnixStreamChannel>(boost::ref(getGlobalIoService()),
                                            boost::cref(endpoint));
   m_channels[endpoint] = channel;
   return channel;
diff --git a/daemon/face/unix-stream-channel-factory.hpp b/daemon/face/unix-stream-channel-factory.hpp
index 8d0a6e7..bf14117 100644
--- a/daemon/face/unix-stream-channel-factory.hpp
+++ b/daemon/face/unix-stream-channel-factory.hpp
@@ -12,22 +12,19 @@
 
 namespace nfd {
 
-class UnixStreamChannelFactory : public ChannelFactory<unix_stream::Endpoint, UnixStreamChannel>
+class UnixStreamChannelFactory : public ChannelFactory
 {
 public:
   /**
    * \brief Exception of UnixStreamChannelFactory
    */
-  struct Error : public ChannelFactory<unix_stream::Endpoint, UnixStreamChannel>::Error
+  struct Error : public ChannelFactory::Error
   {
-    Error(const std::string& what)
-      : ChannelFactory<unix_stream::Endpoint, UnixStreamChannel>::Error(what)
-    {
-    }
+    Error(const std::string& what) : ChannelFactory::Error(what) {}
   };
 
   explicit
-  UnixStreamChannelFactory(boost::asio::io_service& ioService);
+  UnixStreamChannelFactory();
 
   /**
    * \brief Create stream-oriented Unix channel using specified socket path
@@ -57,7 +54,8 @@
   find(const unix_stream::Endpoint& endpoint);
 
 private:
-  boost::asio::io_service& m_ioService;
+  typedef std::map< unix_stream::Endpoint, shared_ptr<UnixStreamChannel> > ChannelMap;
+  ChannelMap m_channels;
 };
 
 } // namespace nfd
diff --git a/daemon/main.cpp b/daemon/main.cpp
index 2c83177..b8165f8 100644
--- a/daemon/main.cpp
+++ b/daemon/main.cpp
@@ -171,7 +171,7 @@
 void
 initializeTcp()
 {
-  g_tcpFactory = new TcpChannelFactory(getGlobalIoService());
+  g_tcpFactory = new TcpChannelFactory();
   g_tcpChannel = g_tcpFactory->create(g_options.m_tcpListen.first,
                                       g_options.m_tcpListen.second);
   g_tcpChannel->listen(
@@ -190,7 +190,7 @@
 void
 initializeUnix()
 {
-  g_unixFactory = new UnixStreamChannelFactory(getGlobalIoService());
+  g_unixFactory = new UnixStreamChannelFactory();
   g_unixChannel = g_unixFactory->create(g_options.m_unixListen);
 
   g_unixChannel->listen(
diff --git a/tests/face/tcp.cpp b/tests/face/tcp.cpp
index 5990ab4..cba8796 100644
--- a/tests/face/tcp.cpp
+++ b/tests/face/tcp.cpp
@@ -17,8 +17,7 @@
 
 BOOST_AUTO_TEST_CASE(ChannelMap)
 {
-  boost::asio::io_service io;
-  TcpChannelFactory factory(io);
+  TcpChannelFactory factory;
   
   shared_ptr<TcpChannel> channel1 = factory.create("127.0.0.1", "20070");
   shared_ptr<TcpChannel> channel1a = factory.create("127.0.0.1", "20070");
@@ -147,7 +146,7 @@
   void
   abortTestCase(const std::string& message)
   {
-    m_ioService.stop();
+    g_io.stop();
     BOOST_FAIL(message);
   }
   
@@ -155,12 +154,11 @@
   void
   afterIo()
   {
-    if (--m_ioRemaining <= 0) m_ioService.stop();
+    if (--m_ioRemaining <= 0)
+      g_io.stop();
   }
 
 public:
-  boost::asio::io_service m_ioService;
-
   int m_ioRemaining;
 
   shared_ptr<Face> m_face1;
@@ -176,13 +174,12 @@
 
 BOOST_FIXTURE_TEST_CASE(EndToEnd, EndToEndFixture)
 {
-  TcpChannelFactory factory(m_ioService);
-  Scheduler scheduler(m_ioService); // to limit the amount of time the test may take
+  TcpChannelFactory factory;
 
   EventId abortEvent =
-    scheduler.scheduleEvent(time::seconds(10),
-                            bind(&EndToEndFixture::abortTestCase, this,
-                                 "TcpChannel error: cannot connect or cannot accept connection"));
+    scheduler::schedule(time::seconds(10),
+                        bind(&EndToEndFixture::abortTestCase, this,
+                             "TcpChannel error: cannot connect or cannot accept connection"));
   
   shared_ptr<TcpChannel> channel1 = factory.create("127.0.0.1", "20070");
   shared_ptr<TcpChannel> channel2 = factory.create("127.0.0.1", "20071");
@@ -196,9 +193,9 @@
                     time::seconds(4));
 
   m_ioRemaining = 2;
-  m_ioService.run();
-  m_ioService.reset();
-  scheduler.cancelEvent(abortEvent);
+  g_io.run();
+  g_io.reset();
+  scheduler::cancel(abortEvent);
 
   BOOST_REQUIRE(static_cast<bool>(m_face1));
   BOOST_REQUIRE(static_cast<bool>(m_face2));
@@ -212,9 +209,9 @@
   // integrated tests needs to check that TcpFace for non-loopback fails these tests...
   
   abortEvent =
-    scheduler.scheduleEvent(time::seconds(10),
-                            bind(&EndToEndFixture::abortTestCase, this,
-                                 "TcpChannel error: cannot send or receive Interest/Data packets"));
+    scheduler::schedule(time::seconds(10),
+                        bind(&EndToEndFixture::abortTestCase, this,
+                             "TcpChannel error: cannot send or receive Interest/Data packets"));
 
   Interest interest1("ndn:/TpnzGvW9R");
   Data     data1    ("ndn:/KfczhUqVix");
@@ -236,8 +233,9 @@
   m_face2->sendData    (data2    );
 
   m_ioRemaining = 4;
-  m_ioService.run();
-  m_ioService.reset();
+  g_io.run();
+  g_io.reset();
+  scheduler::cancel(abortEvent);
 
   BOOST_REQUIRE_EQUAL(m_face1_receivedInterests.size(), 1);
   BOOST_REQUIRE_EQUAL(m_face1_receivedDatas    .size(), 1);
@@ -252,13 +250,12 @@
 
 BOOST_FIXTURE_TEST_CASE(MultipleAccepts, EndToEndFixture)
 {
-  TcpChannelFactory factory(m_ioService);
-  Scheduler scheduler(m_ioService); // to limit the amount of time the test may take
+  TcpChannelFactory factory;
 
   EventId abortEvent =
-    scheduler.scheduleEvent(time::seconds(10),
-                            bind(&EndToEndFixture::abortTestCase, this,
-                                 "TcpChannel error: cannot connect or cannot accept connection"));
+    scheduler::schedule(time::seconds(10),
+                        bind(&EndToEndFixture::abortTestCase, this,
+                             "TcpChannel error: cannot connect or cannot accept connection"));
   
   shared_ptr<TcpChannel> channel1 = factory.create("127.0.0.1", "20070");
   shared_ptr<TcpChannel> channel2 = factory.create("127.0.0.1", "20071");
@@ -272,9 +269,9 @@
                     time::seconds(4)); // very short timeout
 
   m_ioRemaining = 2;
-  m_ioService.run();
-  m_ioService.reset();
-  scheduler.cancelEvent(abortEvent);
+  g_io.run();
+  g_io.reset();
+  scheduler::cancel(abortEvent);
 
   BOOST_CHECK_EQUAL(m_faces.size(), 2);
   
@@ -290,7 +287,7 @@
   BOOST_CHECK_NE(channel3, channel4);
   
   scheduler
-    .scheduleEvent
+    ::schedule
     (time::seconds(1),
      bind(&TcpChannel::connect, channel4,
           "127.0.0.1", "20070",
@@ -303,29 +300,29 @@
   
   m_ioRemaining = 4; // 2 connects and 2 accepts
   abortEvent = 
-    scheduler.scheduleEvent(time::seconds(10),
-                            bind(&EndToEndFixture::abortTestCase, this,
-                                 "TcpChannel error: cannot connect or cannot accept multiple connections"));
+    scheduler::schedule(time::seconds(10),
+                        bind(&EndToEndFixture::abortTestCase, this,
+                             "TcpChannel error: cannot connect or cannot accept multiple connections"));
 
-  scheduler.scheduleEvent(time::seconds(0.5),
-                          bind(&EndToEndFixture::checkFaceList, this, 4));
+  scheduler::schedule(time::seconds(0.5),
+                      bind(&EndToEndFixture::checkFaceList, this, 4));
   
-  m_ioService.run();
-  m_ioService.reset();
-  
+  g_io.run();
+  g_io.reset();
+  scheduler::cancel(abortEvent);
+
   BOOST_CHECK_EQUAL(m_faces.size(), 6);
 }
 
 
 BOOST_FIXTURE_TEST_CASE(FaceClosing, EndToEndFixture)
 {
-  TcpChannelFactory factory(m_ioService);
-  Scheduler scheduler(m_ioService); // to limit the amount of time the test may take
+  TcpChannelFactory factory;
 
   EventId abortEvent =
-    scheduler.scheduleEvent(time::seconds(10),
-                            bind(&EndToEndFixture::abortTestCase, this,
-                                 "TcpChannel error: cannot connect or cannot accept connection"));
+    scheduler::schedule(time::seconds(10),
+                        bind(&EndToEndFixture::abortTestCase, this,
+                             "TcpChannel error: cannot connect or cannot accept connection"));
   
   shared_ptr<TcpChannel> channel1 = factory.create("127.0.0.1", "20070");
   shared_ptr<TcpChannel> channel2 = factory.create("127.0.0.1", "20071");
@@ -339,17 +336,18 @@
                     time::seconds(4)); // very short timeout
 
   m_ioRemaining = 2;
-  BOOST_REQUIRE_NO_THROW(m_ioService.run());
-  m_ioService.reset();
-  scheduler.cancelEvent(abortEvent);
+  g_io.run();
+  // BOOST_REQUIRE_NO_THROW(g_io.run());
+  g_io.reset();
+  scheduler::cancel(abortEvent);
 
   BOOST_CHECK_EQUAL(channel1->size(), 1);
   BOOST_CHECK_EQUAL(channel2->size(), 1);
 
   abortEvent =
-    scheduler.scheduleEvent(time::seconds(10),
-                            bind(&EndToEndFixture::abortTestCase, this,
-                                 "FaceClosing error: cannot properly close faces"));
+    scheduler::schedule(time::seconds(10),
+                        bind(&EndToEndFixture::abortTestCase, this,
+                             "FaceClosing error: cannot properly close faces"));
 
   BOOST_REQUIRE(static_cast<bool>(m_face1));
   BOOST_CHECK(static_cast<bool>(m_face2));
@@ -358,9 +356,9 @@
   // just double check that we are calling the virtual method
   static_pointer_cast<Face>(m_face1)->close();
   
-  BOOST_REQUIRE_NO_THROW(m_ioService.run());
-  m_ioService.reset();
-  scheduler.cancelEvent(abortEvent);
+  BOOST_REQUIRE_NO_THROW(g_io.run());
+  g_io.reset();
+  scheduler::cancel(abortEvent);
 
   // both faces should get closed
   BOOST_CHECK(!static_cast<bool>(m_face1));
diff --git a/tests/face/unix-stream.cpp b/tests/face/unix-stream.cpp
index 8fba080..85bac65 100644
--- a/tests/face/unix-stream.cpp
+++ b/tests/face/unix-stream.cpp
@@ -19,8 +19,7 @@
 
 BOOST_AUTO_TEST_CASE(ChannelMap)
 {
-  boost::asio::io_service io;
-  UnixStreamChannelFactory factory(io);
+  UnixStreamChannelFactory factory;
 
   shared_ptr<UnixStreamChannel> channel1 = factory.create("foo");
   shared_ptr<UnixStreamChannel> channel1a = factory.create("foo");
@@ -113,7 +112,7 @@
   void
   abortTestCase(const std::string& message)
   {
-    m_ioService.stop();
+    g_io.stop();
     BOOST_FAIL(message);
   }
 
@@ -122,12 +121,10 @@
   afterIo()
   {
     if (--m_ioRemaining <= 0)
-      m_ioService.stop();
+      g_io.stop();
   }
 
 protected:
-  boost::asio::io_service m_ioService;
-
   int m_ioRemaining;
 
   shared_ptr<UnixStreamFace> m_face1;
@@ -143,34 +140,33 @@
 
 BOOST_FIXTURE_TEST_CASE(EndToEnd, EndToEndFixture)
 {
-  UnixStreamChannelFactory factory(m_ioService);
-  Scheduler scheduler(m_ioService); // to limit the amount of time the test may take
+  UnixStreamChannelFactory factory;
 
   EventId abortEvent =
-    scheduler.scheduleEvent(time::seconds(1),
-                            bind(&EndToEndFixture::abortTestCase, this,
-                                 "UnixStreamChannel error: cannot connect or cannot accept connection"));
+    scheduler::schedule(time::seconds(1),
+                        bind(&EndToEndFixture::abortTestCase, this,
+                             "UnixStreamChannel error: cannot connect or cannot accept connection"));
 
   shared_ptr<UnixStreamChannel> channel1 = factory.create("foo");
   channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated,   this, _1),
                    bind(&EndToEndFixture::channel1_onConnectFailed, this, _1));
 
   shared_ptr<stream_protocol::socket> client =
-      make_shared<stream_protocol::socket>(boost::ref(m_ioService));
+      make_shared<stream_protocol::socket>(boost::ref(g_io));
   client->async_connect(stream_protocol::endpoint("foo"),
                         bind(&EndToEndFixture::client_onConnect, this, _1));
 
   m_ioRemaining = 2;
-  m_ioService.run();
-  m_ioService.reset();
-  scheduler.cancelEvent(abortEvent);
+  g_io.run();
+  g_io.reset();
+  scheduler::cancel(abortEvent);
 
   BOOST_REQUIRE(static_cast<bool>(m_face1));
 
   abortEvent =
-    scheduler.scheduleEvent(time::seconds(1),
-                            bind(&EndToEndFixture::abortTestCase, this,
-                                 "UnixStreamChannel error: cannot send or receive Interest/Data packets"));
+    scheduler::schedule(time::seconds(1),
+                        bind(&EndToEndFixture::abortTestCase, this,
+                             "UnixStreamChannel error: cannot send or receive Interest/Data packets"));
 
   m_face2 = make_shared<UnixStreamFace>(client);
   m_face2->onReceiveInterest +=
@@ -198,8 +194,8 @@
   m_face2->sendData    (data2    );
 
   m_ioRemaining = 4;
-  m_ioService.run();
-  m_ioService.reset();
+  g_io.run();
+  g_io.reset();
 
   BOOST_REQUIRE_EQUAL(m_face1_receivedInterests.size(), 1);
   BOOST_REQUIRE_EQUAL(m_face1_receivedDatas    .size(), 1);
@@ -214,44 +210,43 @@
 
 BOOST_FIXTURE_TEST_CASE(MultipleAccepts, EndToEndFixture)
 {
-  UnixStreamChannelFactory factory(m_ioService);
-  Scheduler scheduler(m_ioService); // to limit the amount of time the test may take
+  UnixStreamChannelFactory factory;
 
   EventId abortEvent =
-    scheduler.scheduleEvent(time::seconds(1),
-                            bind(&EndToEndFixture::abortTestCase, this,
-                                 "UnixStreamChannel error: cannot connect or cannot accept connection"));
+    scheduler::schedule(time::seconds(1),
+                        bind(&EndToEndFixture::abortTestCase, this,
+                             "UnixStreamChannel error: cannot connect or cannot accept connection"));
 
   shared_ptr<UnixStreamChannel> channel = factory.create("foo");
   channel->listen(bind(&EndToEndFixture::channel_onFaceCreated,   this, _1),
                   bind(&EndToEndFixture::channel_onConnectFailed, this, _1));
 
   shared_ptr<stream_protocol::socket> client1 =
-      make_shared<stream_protocol::socket>(boost::ref(m_ioService));
+      make_shared<stream_protocol::socket>(boost::ref(g_io));
   client1->async_connect(stream_protocol::endpoint("foo"),
                          bind(&EndToEndFixture::client_onConnect, this, _1));
 
   m_ioRemaining = 2;
-  m_ioService.run();
-  m_ioService.reset();
-  scheduler.cancelEvent(abortEvent);
+  g_io.run();
+  g_io.reset();
+  scheduler::cancel(abortEvent);
 
   BOOST_CHECK_EQUAL(m_faces.size(), 1);
 
   abortEvent =
-    scheduler.scheduleEvent(time::seconds(1),
-                            bind(&EndToEndFixture::abortTestCase, this,
-                                 "UnixStreamChannel error: cannot accept multiple connections"));
+    scheduler::schedule(time::seconds(1),
+                        bind(&EndToEndFixture::abortTestCase, this,
+                             "UnixStreamChannel error: cannot accept multiple connections"));
 
   shared_ptr<stream_protocol::socket> client2 =
-      make_shared<stream_protocol::socket>(boost::ref(m_ioService));
+      make_shared<stream_protocol::socket>(boost::ref(g_io));
   client2->async_connect(stream_protocol::endpoint("foo"),
                          bind(&EndToEndFixture::client_onConnect, this, _1));
 
   m_ioRemaining = 2;
-  m_ioService.run();
-  m_ioService.reset();
-  scheduler.cancelEvent(abortEvent);
+  g_io.run();
+  g_io.reset();
+  scheduler::cancel(abortEvent);
 
   BOOST_CHECK_EQUAL(m_faces.size(), 2);
 
@@ -272,9 +267,9 @@
       bind(&EndToEndFixture::face2_onReceiveData, this, _1);
 
   abortEvent =
-    scheduler.scheduleEvent(time::seconds(1),
-                            bind(&EndToEndFixture::abortTestCase, this,
-                                 "UnixStreamChannel error: cannot send or receive Interest/Data packets"));
+    scheduler::schedule(time::seconds(1),
+                        bind(&EndToEndFixture::abortTestCase, this,
+                             "UnixStreamChannel error: cannot send or receive Interest/Data packets"));
 
   Interest interest1("ndn:/TpnzGvW9R");
   Data     data1    ("ndn:/KfczhUqVix");
@@ -296,8 +291,8 @@
   m_face2->sendData    (data2    );
 
   m_ioRemaining = 4;
-  m_ioService.run();
-  m_ioService.reset();
+  g_io.run();
+  g_io.reset();
 
   BOOST_REQUIRE_EQUAL(m_face1_receivedInterests.size(), 1);
   BOOST_REQUIRE_EQUAL(m_face1_receivedDatas    .size(), 1);
@@ -317,34 +312,33 @@
 
 BOOST_FIXTURE_TEST_CASE(UnixStreamFaceLocalControlHeader, EndToEndFixture)
 {
-  UnixStreamChannelFactory factory(m_ioService);
-  Scheduler scheduler(m_ioService); // to limit the amount of time the test may take
+  UnixStreamChannelFactory factory;
 
   EventId abortEvent =
-    scheduler.scheduleEvent(time::seconds(1),
-                            bind(&EndToEndFixture::abortTestCase, this,
-                                 "UnixStreamChannel error: cannot connect or cannot accept connection"));
+    scheduler::schedule(time::seconds(1),
+                        bind(&EndToEndFixture::abortTestCase, this,
+                             "UnixStreamChannel error: cannot connect or cannot accept connection"));
 
   shared_ptr<UnixStreamChannel> channel1 = factory.create("foo");
   channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated,   this, _1),
                    bind(&EndToEndFixture::channel1_onConnectFailed, this, _1));
 
   shared_ptr<stream_protocol::socket> client =
-      make_shared<stream_protocol::socket>(boost::ref(m_ioService));
+      make_shared<stream_protocol::socket>(boost::ref(g_io));
   client->async_connect(stream_protocol::endpoint("foo"),
                         bind(&EndToEndFixture::client_onConnect, this, _1));
 
   m_ioRemaining = 2;
-  m_ioService.run();
-  m_ioService.reset();
-  scheduler.cancelEvent(abortEvent);
+  g_io.run();
+  g_io.reset();
+  scheduler::cancel(abortEvent);
 
   BOOST_REQUIRE(static_cast<bool>(m_face1));
 
   abortEvent =
-    scheduler.scheduleEvent(time::seconds(1),
-                            bind(&EndToEndFixture::abortTestCase, this,
-                                 "UnixStreamChannel error: cannot send or receive Interest/Data packets"));
+    scheduler::schedule(time::seconds(1),
+                        bind(&EndToEndFixture::abortTestCase, this,
+                             "UnixStreamChannel error: cannot send or receive Interest/Data packets"));
 
   m_face2 = make_shared<UnixStreamFace>(client);
   m_face2->onReceiveInterest +=
@@ -393,8 +387,8 @@
   //
 
   m_ioRemaining = 2;
-  m_ioService.run();
-  m_ioService.reset();
+  g_io.run();
+  g_io.reset();
 
   BOOST_REQUIRE_EQUAL(m_face2_receivedInterests.size(), 1);
   BOOST_REQUIRE_EQUAL(m_face2_receivedDatas    .size(), 1);
@@ -428,8 +422,8 @@
   client->async_send(dataWithHeader, bind(&noOp));
 
   m_ioRemaining = 2;
-  m_ioService.run();
-  m_ioService.reset();
+  g_io.run();
+  g_io.reset();
 
   BOOST_REQUIRE_EQUAL(m_face1_receivedInterests.size(), 1);
   BOOST_REQUIRE_EQUAL(m_face1_receivedDatas    .size(), 1);