blob: 24ec85c3bcea113e82aba1e97c902bee912a2e69 [file] [log] [blame]
Alexander Afanasyev20d2c582014-01-26 15:32:51 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08003 * Copyright (C) 2013-2014 Regents of the University of California.
Alexander Afanasyev20d2c582014-01-26 15:32:51 -08004 * See COPYING for copyright and distribution information.
5 */
6
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -08007#include "common.hpp"
Alexander Afanasyev20d2c582014-01-26 15:32:51 -08008
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -08009#include "tcp-transport.hpp"
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080010#include "stream-transport.hpp"
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080011
12namespace ndn {
13
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080014TcpTransport::TcpTransport(const std::string& host, const std::string& port/* = "6363"*/)
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080015 : m_host(host)
16 , m_port(port)
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080017{
18}
19
20TcpTransport::~TcpTransport()
21{
22}
23
24void
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080025TcpTransport::connect(boost::asio::io_service& ioService,
26 const ReceiveCallback& receiveCallback)
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080027{
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080028 if (!static_cast<bool>(m_impl)) {
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080029 Transport::connect(ioService, receiveCallback);
30
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080031 m_impl = make_shared<Impl> (boost::ref(*this),
32 boost::ref(ioService));
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080033 }
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080034
35 boost::asio::ip::tcp::resolver::query query(m_host, m_port);
36 m_impl->connect(query);
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080037}
38
39void
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080040TcpTransport::send(const Block& wire)
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080041{
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080042 m_impl->send(wire);
43}
44
45void
46TcpTransport::send(const Block& header, const Block& payload)
47{
48 m_impl->send(header, payload);
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080049}
50
51void
52TcpTransport::close()
53{
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080054 m_impl->close();
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080055}
56
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080057} // namespace ndn