node+transport: Improving async operations and error reporting
All operations, including connect are fully async
Change-Id: I6c28c4f883d3aa10efbc4af939cf09e0e865c574
diff --git a/src/node.cpp b/src/node.cpp
index cec382c..5449a88 100644
--- a/src/node.cpp
+++ b/src/node.cpp
@@ -39,8 +39,7 @@
// TODO: Properly check if we are already connected to the expected host.
if (!transport_->isConnected())
transport_->connect(ioService_,
- ptr_lib::bind(&Node::onReceiveElement, this, _1),
- ptr_lib::bind(&Node::onTransportError, this));
+ ptr_lib::bind(&Node::onReceiveElement, this, _1));
uint64_t pendingInterestId = PendingInterest::getNextPendingInterestId();
pendingInterestTable_.push_back(ptr_lib::shared_ptr<PendingInterest>(new PendingInterest
@@ -57,8 +56,7 @@
// TODO: Properly check if we are already connected to the expected host.
if (!transport_->isConnected())
transport_->connect(ioService_,
- ptr_lib::bind(&Node::onReceiveElement, this, _1),
- ptr_lib::bind(&Node::onTransportError, this));
+ ptr_lib::bind(&Node::onReceiveElement, this, _1));
transport_->send(data.wireEncode());
}
@@ -212,21 +210,27 @@
if (timeout > 0)
{
processEventsTimeoutTimer_.expires_from_now(boost::posix_time::milliseconds(timeout));
- processEventsTimeoutTimer_.async_wait(func_lib::bind(&Node::shutdown, this));
+ processEventsTimeoutTimer_.async_wait(fireProcessEventsTimeout);
}
try
{
ioService_.run();
ioService_.reset();
}
- catch(Node::Error &)
+ catch(Node::ProcessEventsTimeout &)
{
- ioService_.reset(); // this needed in order to call ioService_.run() again in the future
- throw;
+ // break
}
}
void
+Node::fireProcessEventsTimeout(const boost::system::error_code& error)
+{
+ if (!error) // can fire for some other reason, e.g., cancelled
+ throw Node::ProcessEventsTimeout();
+}
+
+void
Node::checkPitExpire()
{
// Check for PIT entry timeouts. Go backwards through the list so we can erase entries.