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 
35 class TcpTransport : public Transport {
36 public:
42  public:
48  ConnectionInfo(const char *host, unsigned short port = 6363)
49  : host_(host), port_(port)
50  {
51  }
52 
57  const std::string&
58  getHost() const { return host_; }
59 
64  unsigned short
65  getPort() const { return port_; }
66 
67  virtual
68  ~ConnectionInfo();
69 
70  private:
71  std::string host_;
72  unsigned short port_;
73  };
74 
75  TcpTransport();
76 
88  virtual bool
89  isLocal(const Transport::ConnectionInfo& connectionInfo);
90 
100  virtual void
101  connect
102  (const Transport::ConnectionInfo& connectionInfo,
103  ElementListener& elementListener, const OnConnected& onConnected);
104 
110  virtual void
111  send(const uint8_t *data, size_t dataLength);
112 
122  virtual void
123  processEvents();
124 
125  virtual bool
126  getIsConnected();
127 
131  virtual void
132  close();
133 
134 private:
135  ptr_lib::shared_ptr<struct ndn_TcpTransport> transport_;
136  ptr_lib::shared_ptr<DynamicUInt8Vector> elementBuffer_;
137  bool isConnected_;
138  ConnectionInfo connectionInfo_;
139  bool isLocal_;
140 };
141 
142 }
143 
144 #endif
virtual void close()
Close the connection to the host.
Definition: tcp-transport.cpp:110
Definition: transport.hpp:32
Copyright (C) 2013-2016 Regents of the University of California.
Definition: common.hpp:35
const std::string & getHost() const
Get the host given to the constructor.
Definition: tcp-transport.hpp:58
An ElementListener extends an ndn_ElementListener struct to proved an abstract virtual onReceivedElem...
Definition: element-listener.hpp:33
virtual void connect(const Transport::ConnectionInfo &connectionInfo, ElementListener &elementListener, const OnConnected &onConnected)
Connect according to the info in ConnectionInfo, and processEvents() will use elementListener.
Definition: tcp-transport.cpp:69
virtual bool isLocal(const Transport::ConnectionInfo &connectionInfo)
Determine whether this transport connecting according to connectionInfo is to a node on the current m...
Definition: tcp-transport.cpp:46
virtual void send(const uint8_t *data, size_t dataLength)
Set data to the host.
Definition: tcp-transport.cpp:86
virtual void processEvents()
Process any data to receive.
Definition: tcp-transport.cpp:94
A TcpTransport::ConnectionInfo extends Transport::ConnectionInfo to hold the host and port info for t...
Definition: tcp-transport.hpp:41
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:48
Definition: tcp-transport.hpp:35
A Transport::ConnectionInfo is a base class for connection information used by subclasses of Transpor...
Definition: transport.hpp:38
unsigned short getPort() const
Get the port given to the constructor.
Definition: tcp-transport.hpp:65