blob: 71bca137a4433a1e5cd727057a6d06016a272f12 [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Alexander Afanasyev20d2c582014-01-26 15:32:51 -08002/**
Alexander Afanasyevc169a812014-05-20 20:37:29 -04003 * Copyright (c) 2013-2014 Regents of the University of California.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080020 */
21
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080022#include "common.hpp"
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080023
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080024#include "tcp-transport.hpp"
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080025#include "stream-transport.hpp"
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080026
27namespace ndn {
28
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080029TcpTransport::TcpTransport(const std::string& host, const std::string& port/* = "6363"*/)
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080030 : m_host(host)
31 , m_port(port)
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080032{
33}
34
35TcpTransport::~TcpTransport()
36{
37}
38
Alexander Afanasyev52afb3f2014-03-07 09:05:35 +000039void
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080040TcpTransport::connect(boost::asio::io_service& ioService,
41 const ReceiveCallback& receiveCallback)
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080042{
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080043 if (!static_cast<bool>(m_impl)) {
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080044 Transport::connect(ioService, receiveCallback);
Alexander Afanasyev52afb3f2014-03-07 09:05:35 +000045
Alexander Afanasyevb67090a2014-04-29 22:31:01 -070046 m_impl = make_shared<Impl>(ref(*this), ref(ioService));
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080047 }
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080048
49 boost::asio::ip::tcp::resolver::query query(m_host, m_port);
50 m_impl->connect(query);
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080051}
52
Alexander Afanasyev52afb3f2014-03-07 09:05:35 +000053void
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080054TcpTransport::send(const Block& wire)
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080055{
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080056 m_impl->send(wire);
57}
58
59void
60TcpTransport::send(const Block& header, const Block& payload)
61{
62 m_impl->send(header, payload);
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080063}
64
Alexander Afanasyev52afb3f2014-03-07 09:05:35 +000065void
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080066TcpTransport::close()
67{
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080068 m_impl->close();
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080069}
70
Alexander Afanasyev52afb3f2014-03-07 09:05:35 +000071void
72TcpTransport::pause()
73{
74 m_impl->pause();
75}
76
77void
78TcpTransport::resume()
79{
80 m_impl->resume();
81}
82
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080083} // namespace ndn