All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
async-tcp-transport.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
22 #ifndef NDN_ASYNC_TCP_TRANSPORT_HPP
23 #define NDN_ASYNC_TCP_TRANSPORT_HPP
24 
25 // Only compile if ndn-cpp-config.h defines NDN_CPP_HAVE_BOOST_ASIO.
26 #include "../ndn-cpp-config.h"
27 #ifdef NDN_CPP_HAVE_BOOST_ASIO
28 
29 #include <string>
30 #include <boost/asio.hpp>
31 #include "../common.hpp"
32 #include "../c/encoding/element-reader-types.h"
33 #include "transport.hpp"
34 
35 namespace ndn {
36 
43 class AsyncTcpTransport : public Transport {
44 public:
49  class ConnectionInfo : public Transport::ConnectionInfo {
50  public:
56  ConnectionInfo(const char *host, unsigned short port = 6363)
57  : host_(host), port_(port)
58  {
59  }
60 
65  const std::string&
66  getHost() const { return host_; }
67 
72  unsigned short
73  getPort() const { return port_; }
74 
75  virtual
76  ~ConnectionInfo();
77 
78  private:
79  std::string host_;
80  unsigned short port_;
81  };
82 
89  AsyncTcpTransport(boost::asio::io_service& ioService);
90 
102  virtual bool
103  isLocal(const Transport::ConnectionInfo& connectionInfo);
104 
109  virtual bool
110  isAsync();
111 
122  virtual void
123  connect
124  (const Transport::ConnectionInfo& connectionInfo,
125  ElementListener& elementListener, const OnConnected& onConnected);
126 
134  virtual void
135  send(const uint8_t *data, size_t dataLength);
136 
140  virtual void
141  processEvents();
142 
143  virtual bool
144  getIsConnected();
145 
149  virtual void
150  close();
151 
152  virtual ~AsyncTcpTransport();
153 
154 private:
155  boost::asio::io_service& ioService_;
156  // We define SocketTransport in the source file so that we don't have to
157  // include the Boost headers for boost::asio::ip::tcp in this header file.
158  // (We cannot forward declare ip::tcp itself because it is an inner class.)
159  class SocketTransport;
160  ptr_lib::shared_ptr<SocketTransport> socketTransport_;
161  ConnectionInfo connectionInfo_;
162  bool isLocal_;
163 };
164 
165 }
166 
167 #endif // NDN_CPP_HAVE_BOOST_ASIO
168 
169 #endif