transport: remove unused send() overload
Change-Id: I100c1128c9fde203dd6ce1fa9d28188704bc202f
diff --git a/ndn-cxx/face.cpp b/ndn-cxx/face.cpp
index 3da96b7..db4d196 100644
--- a/ndn-cxx/face.cpp
+++ b/ndn-cxx/face.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2020 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -24,6 +24,7 @@
#include "ndn-cxx/impl/face-impl.hpp"
#include "ndn-cxx/net/face-uri.hpp"
#include "ndn-cxx/security/signing-helpers.hpp"
+#include "ndn-cxx/util/config-file.hpp"
#include "ndn-cxx/util/scope.hpp"
#include "ndn-cxx/util/time.hpp"
diff --git a/ndn-cxx/impl/face-impl.hpp b/ndn-cxx/impl/face-impl.hpp
index 70e6028..b5065d1 100644
--- a/ndn-cxx/impl/face-impl.hpp
+++ b/ndn-cxx/impl/face-impl.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2021 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -33,7 +33,6 @@
#include "ndn-cxx/mgmt/nfd/controller.hpp"
#include "ndn-cxx/transport/tcp-transport.hpp"
#include "ndn-cxx/transport/unix-transport.hpp"
-#include "ndn-cxx/util/config-file.hpp"
#include "ndn-cxx/util/logger.hpp"
#include "ndn-cxx/util/scheduler.hpp"
#include "ndn-cxx/util/signal.hpp"
diff --git a/ndn-cxx/transport/detail/stream-transport-impl.hpp b/ndn-cxx/transport/detail/stream-transport-impl.hpp
index 4cd1ff1..68646d6 100644
--- a/ndn-cxx/transport/detail/stream-transport-impl.hpp
+++ b/ndn-cxx/transport/detail/stream-transport-impl.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2021 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -28,6 +28,7 @@
#include <boost/asio/write.hpp>
#include <list>
+#include <queue>
namespace ndn {
namespace detail {
@@ -42,8 +43,7 @@
{
public:
using Impl = StreamTransportImpl<BaseTransport, Protocol>;
- using BlockSequence = std::list<Block>;
- using TransmissionQueue = std::list<BlockSequence>;
+ using TransmissionQueue = std::queue<Block, std::list<Block>>;
StreamTransportImpl(BaseTransport& transport, boost::asio::io_service& ioService)
: m_transport(transport)
@@ -85,7 +85,7 @@
m_transport.m_isConnected = false;
m_transport.m_isReceiving = false;
- m_transmissionQueue.clear();
+ TransmissionQueue{}.swap(m_transmissionQueue); // clear the queue
}
void
@@ -114,20 +114,15 @@
}
void
- send(const Block& wire)
+ send(const Block& block)
{
- BlockSequence sequence;
- sequence.push_back(wire);
- send(std::move(sequence));
- }
+ m_transmissionQueue.push(block);
- void
- send(const Block& header, const Block& payload)
- {
- BlockSequence sequence;
- sequence.push_back(header);
- sequence.push_back(payload);
- send(std::move(sequence));
+ if (m_transport.m_isConnected && m_transmissionQueue.size() == 1) {
+ asyncWrite();
+ }
+ // if not connected or there's another transmission in progress (m_transmissionQueue.size() > 1),
+ // the next write will be scheduled either in connectHandler or in asyncWriteHandler
}
protected:
@@ -162,26 +157,12 @@
}
void
- send(BlockSequence&& sequence)
- {
- m_transmissionQueue.emplace_back(sequence);
-
- if (m_transport.m_isConnected && m_transmissionQueue.size() == 1) {
- asyncWrite();
- }
-
- // if not connected or there is transmission in progress (m_transmissionQueue.size() > 1),
- // next write will be scheduled either in connectHandler or in asyncWriteHandler
- }
-
- void
asyncWrite()
{
BOOST_ASSERT(!m_transmissionQueue.empty());
- boost::asio::async_write(m_socket, m_transmissionQueue.front(),
+ boost::asio::async_write(m_socket, boost::asio::buffer(m_transmissionQueue.front()),
// capture a copy of the shared_ptr to "this" to prevent deallocation
- [this, self = this->shared_from_this(),
- queueItem = m_transmissionQueue.begin()] (const auto& error, size_t) {
+ [this, self = this->shared_from_this()] (const auto& error, size_t) {
if (error) {
if (error == boost::system::errc::operation_canceled) {
// async receive has been explicitly cancelled (e.g., socket close)
@@ -195,7 +176,8 @@
return; // queue has been already cleared
}
- m_transmissionQueue.erase(queueItem);
+ BOOST_ASSERT(!m_transmissionQueue.empty());
+ m_transmissionQueue.pop();
if (!m_transmissionQueue.empty()) {
asyncWrite();
@@ -265,7 +247,6 @@
typename Protocol::socket m_socket;
uint8_t m_inputBuffer[MAX_NDN_PACKET_SIZE];
size_t m_inputBufferSize = 0;
-
TransmissionQueue m_transmissionQueue;
boost::asio::steady_timer m_connectTimer;
bool m_isConnecting = false;
diff --git a/ndn-cxx/transport/tcp-transport.cpp b/ndn-cxx/transport/tcp-transport.cpp
index 512f5e1..0c5e516 100644
--- a/ndn-cxx/transport/tcp-transport.cpp
+++ b/ndn-cxx/transport/tcp-transport.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2019 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -99,13 +99,6 @@
}
void
-TcpTransport::send(const Block& header, const Block& payload)
-{
- BOOST_ASSERT(m_impl != nullptr);
- m_impl->send(header, payload);
-}
-
-void
TcpTransport::close()
{
BOOST_ASSERT(m_impl != nullptr);
diff --git a/ndn-cxx/transport/tcp-transport.hpp b/ndn-cxx/transport/tcp-transport.hpp
index 7cf2a3e..95c28ea 100644
--- a/ndn-cxx/transport/tcp-transport.hpp
+++ b/ndn-cxx/transport/tcp-transport.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2021 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -23,7 +23,6 @@
#define NDN_CXX_TRANSPORT_TCP_TRANSPORT_HPP
#include "ndn-cxx/transport/transport.hpp"
-#include "ndn-cxx/util/config-file.hpp"
#include <boost/asio/ip/tcp.hpp>
@@ -64,9 +63,6 @@
void
send(const Block& wire) override;
- void
- send(const Block& header, const Block& payload) override;
-
/** \brief Create transport with parameters defined in URI
* \throw Transport::Error incorrect URI or unsupported protocol is specified
*/
diff --git a/ndn-cxx/transport/transport.hpp b/ndn-cxx/transport/transport.hpp
index 71e8f99..6fd4374 100644
--- a/ndn-cxx/transport/transport.hpp
+++ b/ndn-cxx/transport/transport.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2021 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -49,50 +49,47 @@
virtual
~Transport() = default;
- /** \brief Asynchronously open the connection.
- * \param ioService io_service to create socket on
- * \param receiveCallback callback function when a TLV block is received; must not be empty
- * \throw boost::system::system_error connection cannot be established
+ /**
+ * \brief Asynchronously open the connection.
+ * \param ioService io_service to create socket on
+ * \param receiveCallback callback function when a TLV block is received; must not be empty
+ * \throw boost::system::system_error connection cannot be established
*/
virtual void
connect(boost::asio::io_service& ioService, ReceiveCallback receiveCallback);
- /** \brief Close the connection.
+ /**
+ * \brief Close the connection.
*/
virtual void
close() = 0;
- /** \brief send a TLV block through the transport
+ /**
+ * \brief Send a TLV block through the transport.
*/
virtual void
- send(const Block& wire) = 0;
+ send(const Block& block) = 0;
- /** \brief send two memory blocks through the transport
- *
- * Scatter/gather API is utilized to send two non-consecutive memory blocks together
- * (as part of the same message in datagram-oriented transports).
- */
- virtual void
- send(const Block& header, const Block& payload) = 0;
-
- /** \brief pause the transport
- * \post the receive callback will not be invoked
- * \note This operation has no effect if transport has been paused,
- * or when connection is being established.
+ /**
+ * \brief Pause the transport, canceling all pending operations.
+ * \post the receive callback will not be invoked
+ * \note This operation has no effect if the transport has been paused,
+ * or when the connection is being established.
*/
virtual void
pause() = 0;
- /** \brief resume the transport
- * \post the receive callback will be invoked
- * \note This operation has no effect if transport is not paused,
- * or when connection is being established.
+ /**
+ * \brief Resume the transport.
+ * \post the receive callback will be invoked
+ * \note This operation has no effect if the transport is not paused,
+ * or when the connection is being established.
*/
virtual void
resume() = 0;
- /** \retval true connection has been established
- * \retval false connection is not yet established or has been closed
+ /**
+ * \brief Return whether the transport is connected.
*/
bool
isConnected() const noexcept
@@ -100,8 +97,9 @@
return m_isConnected;
}
- /** \retval true incoming packets are expected, the receive callback will be invoked
- * \retval false incoming packets are not expected, the receive callback will not be invoked
+ /**
+ * \retval true incoming packets are expected, the receive callback will be invoked
+ * \retval false incoming packets are not expected, the receive callback will not be invoked
*/
bool
isReceiving() const noexcept
diff --git a/ndn-cxx/transport/unix-transport.cpp b/ndn-cxx/transport/unix-transport.cpp
index f1f1526..b8404eb 100644
--- a/ndn-cxx/transport/unix-transport.cpp
+++ b/ndn-cxx/transport/unix-transport.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2020 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -97,13 +97,6 @@
}
void
-UnixTransport::send(const Block& header, const Block& payload)
-{
- BOOST_ASSERT(m_impl != nullptr);
- m_impl->send(header, payload);
-}
-
-void
UnixTransport::close()
{
BOOST_ASSERT(m_impl != nullptr);
diff --git a/ndn-cxx/transport/unix-transport.hpp b/ndn-cxx/transport/unix-transport.hpp
index da19b4c..2d1ef05 100644
--- a/ndn-cxx/transport/unix-transport.hpp
+++ b/ndn-cxx/transport/unix-transport.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2021 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -23,7 +23,6 @@
#define NDN_CXX_TRANSPORT_UNIX_TRANSPORT_HPP
#include "ndn-cxx/transport/transport.hpp"
-#include "ndn-cxx/util/config-file.hpp"
#include <boost/asio/local/stream_protocol.hpp>
@@ -61,9 +60,6 @@
void
send(const Block& wire) override;
- void
- send(const Block& header, const Block& payload) override;
-
/** \brief Create transport with parameters defined in URI
* \throw Transport::Error incorrect URI or unsupported protocol is specified
*/
diff --git a/ndn-cxx/util/dummy-client-face.cpp b/ndn-cxx/util/dummy-client-face.cpp
index 9f2cb9e..017bb76 100644
--- a/ndn-cxx/util/dummy-client-face.cpp
+++ b/ndn-cxx/util/dummy-client-face.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2019 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -32,7 +32,7 @@
namespace ndn {
namespace util {
-class DummyClientFace::Transport : public ndn::Transport
+class DummyClientFace::Transport final : public ndn::Transport
{
public:
void
@@ -45,42 +45,26 @@
}
void
- close() override
+ send(const Block& block) final
+ {
+ onSendBlock(block);
+ }
+
+ void
+ close() final
{
}
void
- pause() override
+ pause() final
{
}
void
- resume() override
+ resume() final
{
}
- void
- send(const Block& wire) override
- {
- onSendBlock(wire);
- }
-
- void
- send(const Block& header, const Block& payload) override
- {
- EncodingBuffer encoder(header.size() + payload.size(), header.size() + payload.size());
- encoder.appendByteArray(header.wire(), header.size());
- encoder.appendByteArray(payload.wire(), payload.size());
-
- this->send(encoder.block());
- }
-
- boost::asio::io_service&
- getIoService()
- {
- return *m_ioService;
- }
-
public:
Signal<Transport, Block> onSendBlock;
};
diff --git a/ndn-cxx/util/dummy-client-face.hpp b/ndn-cxx/util/dummy-client-face.hpp
index 66f4e21..599d934 100644
--- a/ndn-cxx/util/dummy-client-face.hpp
+++ b/ndn-cxx/util/dummy-client-face.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2021 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -29,7 +29,7 @@
namespace ndn {
namespace util {
-/** \brief a client-side face for unit testing
+/** \brief A client-side face for unit testing.
*/
class DummyClientFace : public ndn::Face
{
@@ -98,7 +98,7 @@
DummyClientFace(boost::asio::io_service& ioService, KeyChain& keyChain,
const Options& options = Options());
- ~DummyClientFace();
+ ~DummyClientFace() override;
/** \brief cause the Face to receive an interest
*/
diff --git a/tests/unit/face.t.cpp b/tests/unit/face.t.cpp
index eaab9b6..5fdfd1c 100644
--- a/tests/unit/face.t.cpp
+++ b/tests/unit/face.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2021 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -23,6 +23,7 @@
#include "ndn-cxx/lp/tags.hpp"
#include "ndn-cxx/transport/tcp-transport.hpp"
#include "ndn-cxx/transport/unix-transport.hpp"
+#include "ndn-cxx/util/config-file.hpp"
#include "ndn-cxx/util/dummy-client-face.hpp"
#include "ndn-cxx/util/scheduler.hpp"