| /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| * Copyright (C) 2014 Named Data Networking Project |
| * See COPYING for copyright and distribution information. |
| #include "limited-io.hpp" |
| #include "core/logger.hpp" |
| NFD_LOG_INIT("LimitedIo"); |
| const int LimitedIo::UNLIMITED_OPS = std::numeric_limits<int>::max(); |
| const time::Duration LimitedIo::UNLIMITED_TIME = time::nanoseconds(-1); |
| LimitedIo::run(int nOpsLimit, time::Duration nTimeLimit) |
| BOOST_ASSERT(!m_isRunning); |
| m_nOpsRemaining = nOpsLimit; |
| if (nTimeLimit != UNLIMITED_TIME) { |
| m_timeout = scheduler::schedule(nTimeLimit, bind(&LimitedIo::afterTimeout, this)); |
| getGlobalIoService().run(); |
| catch (std::exception& ex) { |
| NFD_LOG_ERROR("g_io.run() exception: " << ex.what()); |
| getGlobalIoService().reset(); |
| scheduler::cancel(m_timeout); |
| if (m_nOpsRemaining <= 0) { |
| getGlobalIoService().stop(); |
| LimitedIo::afterTimeout() |
| getGlobalIoService().stop(); |
| LimitedIo::getLastException() const |