blob: fafe98740bcbef592eaef0eab376a98d372e0881 [file] [log] [blame]
Alexander Afanasyev20d2c582014-01-26 15:32:51 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07003 * Copyright (c) 2013-2014, Regents of the University of California.
4 * All rights reserved.
5 *
6 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
7 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
8 *
9 * This file licensed under New BSD License. See COPYING for detailed information about
10 * ndn-cxx library copyright, permissions, and redistribution restrictions.
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080011 */
12
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080013#include "common.hpp"
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080014
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080015#include "tcp-transport.hpp"
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080016#include "stream-transport.hpp"
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080017
18namespace ndn {
19
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080020TcpTransport::TcpTransport(const std::string& host, const std::string& port/* = "6363"*/)
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080021 : m_host(host)
22 , m_port(port)
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080023{
24}
25
26TcpTransport::~TcpTransport()
27{
28}
29
Alexander Afanasyev52afb3f2014-03-07 09:05:35 +000030void
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080031TcpTransport::connect(boost::asio::io_service& ioService,
32 const ReceiveCallback& receiveCallback)
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080033{
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080034 if (!static_cast<bool>(m_impl)) {
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080035 Transport::connect(ioService, receiveCallback);
Alexander Afanasyev52afb3f2014-03-07 09:05:35 +000036
Alexander Afanasyevb67090a2014-04-29 22:31:01 -070037 m_impl = make_shared<Impl>(ref(*this), ref(ioService));
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080038 }
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080039
40 boost::asio::ip::tcp::resolver::query query(m_host, m_port);
41 m_impl->connect(query);
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080042}
43
Alexander Afanasyev52afb3f2014-03-07 09:05:35 +000044void
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080045TcpTransport::send(const Block& wire)
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080046{
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080047 m_impl->send(wire);
48}
49
50void
51TcpTransport::send(const Block& header, const Block& payload)
52{
53 m_impl->send(header, payload);
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080054}
55
Alexander Afanasyev52afb3f2014-03-07 09:05:35 +000056void
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080057TcpTransport::close()
58{
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080059 m_impl->close();
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080060}
61
Alexander Afanasyev52afb3f2014-03-07 09:05:35 +000062void
63TcpTransport::pause()
64{
65 m_impl->pause();
66}
67
68void
69TcpTransport::resume()
70{
71 m_impl->resume();
72}
73
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080074} // namespace ndn