All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
tcp-transport.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
22 #ifndef NDN_TCP_TRANSPORT_HPP
23 #define NDN_TCP_TRANSPORT_HPP
24 
25 #include <string>
26 #include "../common.hpp"
27 #include "transport.hpp"
28 
29 struct ndn_TcpTransport;
30 
31 namespace ndn {
32 
33 class DynamicUInt8Vector;
34 
39 class TcpTransport : public Transport {
40 public:
46  public:
52  ConnectionInfo(const char *host, unsigned short port = 6363)
53  : host_(host), port_(port)
54  {
55  }
56 
61  const std::string&
62  getHost() const { return host_; }
63 
68  unsigned short
69  getPort() const { return port_; }
70 
71  virtual
72  ~ConnectionInfo();
73 
74  private:
75  std::string host_;
76  unsigned short port_;
77  };
78 
79  TcpTransport();
80 
92  virtual bool
93  isLocal(const Transport::ConnectionInfo& connectionInfo);
94 
100  virtual bool
101  isAsync();
102 
112  virtual void
113  connect
114  (const Transport::ConnectionInfo& connectionInfo,
115  ElementListener& elementListener, const OnConnected& onConnected);
116 
122  virtual void
123  send(const uint8_t *data, size_t dataLength);
124 
134  virtual void
135  processEvents();
136 
137  virtual bool
138  getIsConnected();
139 
143  virtual void
144  close();
145 
146 private:
147  ptr_lib::shared_ptr<struct ndn_TcpTransport> transport_;
148  ptr_lib::shared_ptr<DynamicUInt8Vector> elementBuffer_;
149  bool isConnected_;
150  ConnectionInfo connectionInfo_;
151  bool isLocal_;
152 };
153 
154 }
155 
156 #endif
A Transport object is used by Face to send packets and to listen for incoming packets.
Definition: transport.hpp:36
const std::string & getHost() const
Get the host given to the constructor.
Definition: tcp-transport.hpp:62
An ElementListener extends an ndn_ElementListener struct to proved an abstract virtual onReceivedElem...
Definition: element-listener.hpp:33
virtual void processEvents()
Process any data to receive.
virtual void send(const uint8_t *data, size_t dataLength)
Send data to the host.
virtual bool isLocal(const Transport::ConnectionInfo &connectionInfo)
Determine whether this transport connecting according to connectionInfo is to a node on the current m...
A TcpTransport::ConnectionInfo extends Transport::ConnectionInfo to hold the host and port info for t...
Definition: tcp-transport.hpp:45
Definition: transport-types.h:35
ConnectionInfo(const char *host, unsigned short port=6363)
Create a ConnectionInfo with the given host and port.
Definition: tcp-transport.hpp:52
TcpTransport extends the Transport interface to implement communication over TCP. ...
Definition: tcp-transport.hpp:39
virtual void close()
Close the connection to the host.
A Transport::ConnectionInfo is a base class for connection information used by subclasses of Transpor...
Definition: transport.hpp:42
virtual bool isAsync()
Override to return false since connect does not need to use the onConnected callback.
virtual void connect(const Transport::ConnectionInfo &connectionInfo, ElementListener &elementListener, const OnConnected &onConnected)
Connect according to the info in ConnectionInfo, and processEvents() will use elementListener.
unsigned short getPort() const
Get the port given to the constructor.
Definition: tcp-transport.hpp:69