node+transport: Improving async operations and error reporting
All operations, including connect are fully async
Change-Id: I6c28c4f883d3aa10efbc4af939cf09e0e865c574
diff --git a/include/ndn-cpp/transport/transport.hpp b/include/ndn-cpp/transport/transport.hpp
index 59af6d1..064107b 100644
--- a/include/ndn-cpp/transport/transport.hpp
+++ b/include/ndn-cpp/transport/transport.hpp
@@ -12,11 +12,14 @@
#include <vector>
#include <boost/asio.hpp>
+#include <boost/lexical_cast.hpp>
namespace ndn {
class Transport {
public:
+ struct Error : public std::runtime_error { inline Error(const boost::system::error_code &code, const std::string &msg); };
+
typedef ptr_lib::function<void (const Block &wire)> ReceiveCallback;
typedef ptr_lib::function<void ()> ErrorCallback;
@@ -33,8 +36,7 @@
*/
inline virtual void
connect(boost::asio::io_service &io_service,
- const ReceiveCallback &receiveCallback,
- const ErrorCallback &errorCallback);
+ const ReceiveCallback &receiveCallback);
/**
* Close the connection.
@@ -61,7 +63,6 @@
boost::asio::io_service *ioService_;
bool isConnected_;
ReceiveCallback receiveCallback_;
- ErrorCallback errorCallback_;
};
inline
@@ -71,6 +72,11 @@
{
}
+inline Transport::Error::Error(const boost::system::error_code &code, const std::string &msg)
+ : std::runtime_error(msg + (code.value() ? " (" + code.category().message(code.value()) + ")" : ""))
+{
+}
+
inline
Transport::~Transport()
{
@@ -78,12 +84,10 @@
inline void
Transport::connect(boost::asio::io_service &ioService,
- const ReceiveCallback &receiveCallback,
- const ErrorCallback &errorCallback)
+ const ReceiveCallback &receiveCallback)
{
ioService_ = &ioService;
receiveCallback_ = receiveCallback;
- errorCallback_ = errorCallback;
}
inline bool