blob: 8f835a6ddc385976a1c51247b63a1e18e1959975 [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 Afanasyev5964fb72014-02-18 12:42:45 -080037 m_impl = make_shared<Impl> (boost::ref(*this),
38 boost::ref(ioService));
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080039 }
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080040
41 boost::asio::ip::tcp::resolver::query query(m_host, m_port);
42 m_impl->connect(query);
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080043}
44
Alexander Afanasyev52afb3f2014-03-07 09:05:35 +000045void
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080046TcpTransport::send(const Block& wire)
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080047{
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080048 m_impl->send(wire);
49}
50
51void
52TcpTransport::send(const Block& header, const Block& payload)
53{
54 m_impl->send(header, payload);
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080055}
56
Alexander Afanasyev52afb3f2014-03-07 09:05:35 +000057void
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080058TcpTransport::close()
59{
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080060 m_impl->close();
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080061}
62
Alexander Afanasyev52afb3f2014-03-07 09:05:35 +000063void
64TcpTransport::pause()
65{
66 m_impl->pause();
67}
68
69void
70TcpTransport::resume()
71{
72 m_impl->resume();
73}
74
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080075} // namespace ndn