All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
tcp-transport.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
7 #include "common.hpp"
8 
9 #include "tcp-transport.hpp"
10 #include "stream-transport.hpp"
11 
12 namespace ndn {
13 
14 TcpTransport::TcpTransport(const std::string& host, const std::string& port/* = "6363"*/)
15  : m_host(host)
16  , m_port(port)
17 {
18 }
19 
21 {
22 }
23 
24 void
25 TcpTransport::connect(boost::asio::io_service& ioService,
26  const ReceiveCallback& receiveCallback)
27 {
28  if (!static_cast<bool>(m_impl)) {
29  Transport::connect(ioService, receiveCallback);
30 
31  m_impl = make_shared<Impl> (boost::ref(*this),
32  boost::ref(ioService));
33  }
34 
35  boost::asio::ip::tcp::resolver::query query(m_host, m_port);
36  m_impl->connect(query);
37 }
38 
39 void
41 {
42  m_impl->send(wire);
43 }
44 
45 void
46 TcpTransport::send(const Block& header, const Block& payload)
47 {
48  m_impl->send(header, payload);
49 }
50 
51 void
53 {
54  m_impl->close();
55 }
56 
57 void
59 {
60  m_impl->pause();
61 }
62 
63 void
65 {
66  m_impl->resume();
67 }
68 
69 } // namespace ndn
virtual void connect(boost::asio::io_service &io_service, const ReceiveCallback &receiveCallback)
Connect transport.
Definition: transport.hpp:116
ptr_lib::function< void(const Block &wire)> ReceiveCallback
Definition: transport.hpp:25
virtual void resume()
virtual void pause()
Class representing wire element of the NDN packet.
Definition: block.hpp:26
virtual void connect(boost::asio::io_service &ioService, const ReceiveCallback &receiveCallback)
Connect transport.
virtual void send(const Block &wire)
Set data to the host.
virtual void close()
Close the connection.
TcpTransport(const std::string &host, const std::string &port="6363")