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 #include <string>
26 #include "../common.hpp"
27 #include "../c/encoding/element-reader-types.h"
28 #include "transport.hpp"
29 
30 namespace boost { namespace asio { class io_service; }}
31 
32 namespace ndn {
33 
40 class AsyncTcpTransport : public Transport {
41 public:
47  public:
53  ConnectionInfo(const char *host, unsigned short port = 6363)
54  : host_(host), port_(port)
55  {
56  }
57 
62  const std::string&
63  getHost() const { return host_; }
64 
69  unsigned short
70  getPort() const { return port_; }
71 
72  virtual
73  ~ConnectionInfo();
74 
75  private:
76  std::string host_;
77  unsigned short port_;
78  };
79 
86  AsyncTcpTransport(boost::asio::io_service& ioService);
87 
99  virtual bool
100  isLocal(const Transport::ConnectionInfo& connectionInfo);
101 
112  virtual void
113  connect
114  (const Transport::ConnectionInfo& connectionInfo,
115  ElementListener& elementListener, const OnConnected& onConnected);
116 
124  virtual void
125  send(const uint8_t *data, size_t dataLength);
126 
130  virtual void
131  processEvents();
132 
133  virtual bool
134  getIsConnected();
135 
139  virtual void
140  close();
141 
142  virtual ~AsyncTcpTransport();
143 
144 private:
145  boost::asio::io_service& ioService_;
146  // We define SocketTransport in the source file so that we don't have to
147  // include the Boost headers for boost::asio::ip::tcp in this header file.
148  // (We cannot forward declare ip::tcp itself because it is an inner class.)
149  class SocketTransport;
150  ptr_lib::shared_ptr<SocketTransport> socketTransport_;
151  ConnectionInfo connectionInfo_;
152  bool isLocal_;
153 };
154 
155 }
156 
157 #endif
virtual void close()
Close the connection to the host.
Definition: transport.hpp:32
Copyright (C) 2013-2016 Regents of the University of California.
Definition: common.hpp:35
Copyright (C) 2015-2016 Regents of the University of California.
Definition: threadsafe-face.hpp:27
An ElementListener extends an ndn_ElementListener struct to proved an abstract virtual onReceivedElem...
Definition: element-listener.hpp:33
An AsyncTcpTransport::ConnectionInfo extends Transport::ConnectionInfo to hold the host and port info...
Definition: async-tcp-transport.hpp:46
virtual void processEvents()
Do nothing since the asio io_service reads the socket.
virtual void send(const uint8_t *data, size_t dataLength)
Set data to the host.
unsigned short getPort() const
Get the port given to the constructor.
Definition: async-tcp-transport.hpp:70
const std::string & getHost() const
Get the host given to the constructor.
Definition: async-tcp-transport.hpp:63
AsyncTcpTransport extends Transport for async communication over TCP using Boost's asio io_service...
Definition: async-tcp-transport.hpp:40
virtual void connect(const Transport::ConnectionInfo &connectionInfo, ElementListener &elementListener, const OnConnected &onConnected)
Connect according to the info in connectionInfo, and use elementListener.
AsyncTcpTransport(boost::asio::io_service &ioService)
Create an AsyncTcpTransport in the unconnected state.
A Transport::ConnectionInfo is a base class for connection information used by subclasses of Transpor...
Definition: transport.hpp:38
virtual bool isLocal(const Transport::ConnectionInfo &connectionInfo)
Determine whether this transport connecting according to connectionInfo is to a node on the current m...
ConnectionInfo(const char *host, unsigned short port=6363)
Create a ConnectionInfo with the given host and port.
Definition: async-tcp-transport.hpp:53