Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 2 | /* |
Davide Pesavento | 5d64263 | 2023-10-03 00:36:08 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2023, Regents of the University of California, |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
| 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | */ |
| 25 | |
| 26 | #ifndef NFD_DAEMON_FACE_STREAM_TRANSPORT_HPP |
| 27 | #define NFD_DAEMON_FACE_STREAM_TRANSPORT_HPP |
| 28 | |
| 29 | #include "transport.hpp" |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 30 | #include "socket-utils.hpp" |
Davide Pesavento | 2cae8ca | 2019-04-18 20:48:05 -0400 | [diff] [blame] | 31 | #include "common/global.hpp" |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 32 | |
| 33 | #include <queue> |
| 34 | |
Davide Pesavento | 5d64263 | 2023-10-03 00:36:08 -0400 | [diff] [blame] | 35 | #include <boost/asio/defer.hpp> |
Davide Pesavento | a9b09b6 | 2022-06-04 14:07:25 -0400 | [diff] [blame] | 36 | #include <boost/asio/write.hpp> |
| 37 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 38 | namespace nfd::face { |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 39 | |
Davide Pesavento | c0df94e | 2023-10-08 19:26:55 -0400 | [diff] [blame] | 40 | /** |
| 41 | * \brief Implements a Transport for stream-based protocols. |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 42 | * |
Davide Pesavento | c0df94e | 2023-10-08 19:26:55 -0400 | [diff] [blame] | 43 | * \tparam Protocol a stream-based protocol in Boost.Asio |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 44 | */ |
| 45 | template<class Protocol> |
| 46 | class StreamTransport : public Transport |
| 47 | { |
| 48 | public: |
Davide Pesavento | a599d2a | 2022-02-16 18:52:43 -0500 | [diff] [blame] | 49 | using protocol = Protocol; |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 50 | |
Davide Pesavento | c0df94e | 2023-10-08 19:26:55 -0400 | [diff] [blame] | 51 | /** |
| 52 | * \brief Construct stream transport. |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 53 | * |
Davide Pesavento | c0df94e | 2023-10-08 19:26:55 -0400 | [diff] [blame] | 54 | * \param socket Protocol-specific socket for the created transport |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 55 | */ |
| 56 | explicit |
| 57 | StreamTransport(typename protocol::socket&& socket); |
| 58 | |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 59 | ssize_t |
| 60 | getSendQueueLength() override; |
| 61 | |
Davide Pesavento | 8728a25 | 2015-11-06 04:01:22 +0100 | [diff] [blame] | 62 | protected: |
Davide Pesavento | 1816d4b | 2017-07-02 12:20:48 -0400 | [diff] [blame] | 63 | void |
Davide Pesavento | b84bd3a | 2016-04-22 02:21:45 +0200 | [diff] [blame] | 64 | doClose() override; |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 65 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 66 | void |
| 67 | deferredClose(); |
| 68 | |
Davide Pesavento | 1816d4b | 2017-07-02 12:20:48 -0400 | [diff] [blame] | 69 | void |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 70 | doSend(const Block& packet) override; |
Davide Pesavento | 8728a25 | 2015-11-06 04:01:22 +0100 | [diff] [blame] | 71 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 72 | void |
| 73 | sendFromQueue(); |
| 74 | |
| 75 | void |
| 76 | handleSend(const boost::system::error_code& error, |
| 77 | size_t nBytesSent); |
| 78 | |
| 79 | void |
Weiwei Liu | dcdf621 | 2016-08-31 14:34:22 -0700 | [diff] [blame] | 80 | startReceive(); |
| 81 | |
| 82 | void |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 83 | handleReceive(const boost::system::error_code& error, |
| 84 | size_t nBytesReceived); |
| 85 | |
| 86 | void |
| 87 | processErrorCode(const boost::system::error_code& error); |
| 88 | |
Weiwei Liu | dcdf621 | 2016-08-31 14:34:22 -0700 | [diff] [blame] | 89 | virtual void |
| 90 | handleError(const boost::system::error_code& error); |
| 91 | |
| 92 | void |
| 93 | resetReceiveBuffer(); |
| 94 | |
| 95 | void |
| 96 | resetSendQueue(); |
| 97 | |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 98 | size_t |
| 99 | getSendQueueBytes() const; |
| 100 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 101 | protected: |
| 102 | typename protocol::socket m_socket; |
| 103 | |
Davide Pesavento | a314808 | 2018-04-12 18:21:54 -0400 | [diff] [blame] | 104 | NFD_LOG_MEMBER_DECL(); |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 105 | |
| 106 | private: |
Davide Pesavento | 8728a25 | 2015-11-06 04:01:22 +0100 | [diff] [blame] | 107 | uint8_t m_receiveBuffer[ndn::MAX_NDN_PACKET_SIZE]; |
| 108 | size_t m_receiveBufferSize; |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 109 | std::queue<Block> m_sendQueue; |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 110 | size_t m_sendQueueBytes; |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 111 | }; |
| 112 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 113 | |
| 114 | template<class T> |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 115 | StreamTransport<T>::StreamTransport(typename StreamTransport::protocol::socket&& socket) |
| 116 | : m_socket(std::move(socket)) |
Davide Pesavento | 8728a25 | 2015-11-06 04:01:22 +0100 | [diff] [blame] | 117 | , m_receiveBufferSize(0) |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 118 | , m_sendQueueBytes(0) |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 119 | { |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 120 | // No queue capacity is set because there is no theoretical limit to the size of m_sendQueue. |
| 121 | // Therefore, protecting against send queue overflows is less critical than in other transport |
| 122 | // types. Instead, we use the default threshold specified in the GenericLinkService options. |
| 123 | |
Weiwei Liu | dcdf621 | 2016-08-31 14:34:22 -0700 | [diff] [blame] | 124 | startReceive(); |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | template<class T> |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 128 | ssize_t |
| 129 | StreamTransport<T>::getSendQueueLength() |
| 130 | { |
| 131 | ssize_t queueLength = getTxQueueLength(m_socket.native_handle()); |
| 132 | if (queueLength == QUEUE_ERROR) { |
| 133 | NFD_LOG_FACE_WARN("Failed to obtain send queue length from socket: " << std::strerror(errno)); |
| 134 | } |
| 135 | return getSendQueueBytes() + std::max<ssize_t>(0, queueLength); |
| 136 | } |
| 137 | |
| 138 | template<class T> |
Davide Pesavento | 8728a25 | 2015-11-06 04:01:22 +0100 | [diff] [blame] | 139 | void |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 140 | StreamTransport<T>::doClose() |
| 141 | { |
| 142 | NFD_LOG_FACE_TRACE(__func__); |
| 143 | |
| 144 | if (m_socket.is_open()) { |
| 145 | // Cancel all outstanding operations and shutdown the socket |
| 146 | // so that no further sends or receives are possible. |
| 147 | // Use the non-throwing variants and ignore errors, if any. |
| 148 | boost::system::error_code error; |
| 149 | m_socket.cancel(error); |
Davide Pesavento | d91fe6d | 2023-10-04 21:40:02 -0400 | [diff] [blame] | 150 | m_socket.shutdown(boost::asio::socket_base::shutdown_both, error); |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | // Ensure that the Transport stays alive at least until |
| 154 | // all pending handlers are dispatched |
Davide Pesavento | 5d64263 | 2023-10-03 00:36:08 -0400 | [diff] [blame] | 155 | boost::asio::defer(getGlobalIoService(), [this] { deferredClose(); }); |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 156 | |
Davide Pesavento | 1816d4b | 2017-07-02 12:20:48 -0400 | [diff] [blame] | 157 | // Some bug or feature of Boost.Asio (see https://redmine.named-data.net/issues/1856): |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 158 | // |
| 159 | // When doClose is called from a socket event handler (e.g., from handleReceive), |
| 160 | // m_socket.shutdown() does not trigger the cancellation of the handleSend callback. |
| 161 | // Instead, handleSend is invoked as nothing bad happened. |
| 162 | // |
| 163 | // In order to prevent the assertion in handleSend from failing, we clear the queue |
| 164 | // and close the socket in deferredClose, i.e., after all callbacks scheduled up to |
| 165 | // this point have been executed. If more send operations are scheduled after this |
| 166 | // point, they will fail because the socket has been shutdown, and their callbacks |
| 167 | // will be invoked with error code == asio::error::shut_down. |
| 168 | } |
| 169 | |
| 170 | template<class T> |
Davide Pesavento | 8728a25 | 2015-11-06 04:01:22 +0100 | [diff] [blame] | 171 | void |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 172 | StreamTransport<T>::deferredClose() |
| 173 | { |
| 174 | NFD_LOG_FACE_TRACE(__func__); |
| 175 | |
Weiwei Liu | dcdf621 | 2016-08-31 14:34:22 -0700 | [diff] [blame] | 176 | resetSendQueue(); |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 177 | |
| 178 | // use the non-throwing variant and ignore errors, if any |
| 179 | boost::system::error_code error; |
| 180 | m_socket.close(error); |
| 181 | |
| 182 | this->setState(TransportState::CLOSED); |
| 183 | } |
| 184 | |
| 185 | template<class T> |
Davide Pesavento | 8728a25 | 2015-11-06 04:01:22 +0100 | [diff] [blame] | 186 | void |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 187 | StreamTransport<T>::doSend(const Block& packet) |
Davide Pesavento | 8728a25 | 2015-11-06 04:01:22 +0100 | [diff] [blame] | 188 | { |
| 189 | NFD_LOG_FACE_TRACE(__func__); |
| 190 | |
Weiwei Liu | dcdf621 | 2016-08-31 14:34:22 -0700 | [diff] [blame] | 191 | if (getState() != TransportState::UP) |
| 192 | return; |
| 193 | |
Davide Pesavento | 8728a25 | 2015-11-06 04:01:22 +0100 | [diff] [blame] | 194 | bool wasQueueEmpty = m_sendQueue.empty(); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 195 | m_sendQueue.push(packet); |
| 196 | m_sendQueueBytes += packet.size(); |
Davide Pesavento | 8728a25 | 2015-11-06 04:01:22 +0100 | [diff] [blame] | 197 | |
| 198 | if (wasQueueEmpty) |
| 199 | sendFromQueue(); |
| 200 | } |
| 201 | |
| 202 | template<class T> |
| 203 | void |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 204 | StreamTransport<T>::sendFromQueue() |
| 205 | { |
| 206 | boost::asio::async_write(m_socket, boost::asio::buffer(m_sendQueue.front()), |
Davide Pesavento | e4b2238 | 2018-06-10 14:37:24 -0400 | [diff] [blame] | 207 | [this] (auto&&... args) { this->handleSend(std::forward<decltype(args)>(args)...); }); |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | template<class T> |
Davide Pesavento | 8728a25 | 2015-11-06 04:01:22 +0100 | [diff] [blame] | 211 | void |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 212 | StreamTransport<T>::handleSend(const boost::system::error_code& error, |
| 213 | size_t nBytesSent) |
| 214 | { |
| 215 | if (error) |
| 216 | return processErrorCode(error); |
| 217 | |
| 218 | NFD_LOG_FACE_TRACE("Successfully sent: " << nBytesSent << " bytes"); |
| 219 | |
| 220 | BOOST_ASSERT(!m_sendQueue.empty()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 221 | BOOST_ASSERT(m_sendQueue.front().size() == nBytesSent); |
| 222 | m_sendQueueBytes -= nBytesSent; |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 223 | m_sendQueue.pop(); |
| 224 | |
| 225 | if (!m_sendQueue.empty()) |
| 226 | sendFromQueue(); |
| 227 | } |
| 228 | |
| 229 | template<class T> |
Davide Pesavento | 8728a25 | 2015-11-06 04:01:22 +0100 | [diff] [blame] | 230 | void |
Weiwei Liu | dcdf621 | 2016-08-31 14:34:22 -0700 | [diff] [blame] | 231 | StreamTransport<T>::startReceive() |
| 232 | { |
| 233 | BOOST_ASSERT(getState() == TransportState::UP); |
| 234 | |
| 235 | m_socket.async_receive(boost::asio::buffer(m_receiveBuffer + m_receiveBufferSize, |
| 236 | ndn::MAX_NDN_PACKET_SIZE - m_receiveBufferSize), |
Davide Pesavento | e4b2238 | 2018-06-10 14:37:24 -0400 | [diff] [blame] | 237 | [this] (auto&&... args) { this->handleReceive(std::forward<decltype(args)>(args)...); }); |
Weiwei Liu | dcdf621 | 2016-08-31 14:34:22 -0700 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | template<class T> |
| 241 | void |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 242 | StreamTransport<T>::handleReceive(const boost::system::error_code& error, |
| 243 | size_t nBytesReceived) |
| 244 | { |
| 245 | if (error) |
| 246 | return processErrorCode(error); |
| 247 | |
| 248 | NFD_LOG_FACE_TRACE("Received: " << nBytesReceived << " bytes"); |
| 249 | |
Davide Pesavento | 8728a25 | 2015-11-06 04:01:22 +0100 | [diff] [blame] | 250 | m_receiveBufferSize += nBytesReceived; |
Davide Pesavento | a599d2a | 2022-02-16 18:52:43 -0500 | [diff] [blame] | 251 | auto bufferView = ndn::make_span(m_receiveBuffer, m_receiveBufferSize); |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 252 | size_t offset = 0; |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 253 | bool isOk = true; |
Davide Pesavento | a599d2a | 2022-02-16 18:52:43 -0500 | [diff] [blame] | 254 | while (offset < bufferView.size()) { |
Davide Pesavento | 1816d4b | 2017-07-02 12:20:48 -0400 | [diff] [blame] | 255 | Block element; |
Davide Pesavento | a599d2a | 2022-02-16 18:52:43 -0500 | [diff] [blame] | 256 | std::tie(isOk, element) = Block::fromBuffer(bufferView.subspan(offset)); |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 257 | if (!isOk) |
| 258 | break; |
| 259 | |
| 260 | offset += element.size(); |
Davide Pesavento | a599d2a | 2022-02-16 18:52:43 -0500 | [diff] [blame] | 261 | BOOST_ASSERT(offset <= bufferView.size()); |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 262 | |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 263 | this->receive(element); |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Davide Pesavento | 8728a25 | 2015-11-06 04:01:22 +0100 | [diff] [blame] | 266 | if (!isOk && m_receiveBufferSize == ndn::MAX_NDN_PACKET_SIZE && offset == 0) { |
Davide Pesavento | 1816d4b | 2017-07-02 12:20:48 -0400 | [diff] [blame] | 267 | NFD_LOG_FACE_ERROR("Failed to parse incoming packet or packet too large to process"); |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 268 | this->setState(TransportState::FAILED); |
| 269 | doClose(); |
| 270 | return; |
| 271 | } |
| 272 | |
| 273 | if (offset > 0) { |
Davide Pesavento | 8728a25 | 2015-11-06 04:01:22 +0100 | [diff] [blame] | 274 | if (offset != m_receiveBufferSize) { |
| 275 | std::copy(m_receiveBuffer + offset, m_receiveBuffer + m_receiveBufferSize, m_receiveBuffer); |
| 276 | m_receiveBufferSize -= offset; |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 277 | } |
| 278 | else { |
Davide Pesavento | 8728a25 | 2015-11-06 04:01:22 +0100 | [diff] [blame] | 279 | m_receiveBufferSize = 0; |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 280 | } |
| 281 | } |
| 282 | |
Weiwei Liu | dcdf621 | 2016-08-31 14:34:22 -0700 | [diff] [blame] | 283 | startReceive(); |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | template<class T> |
Davide Pesavento | 8728a25 | 2015-11-06 04:01:22 +0100 | [diff] [blame] | 287 | void |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 288 | StreamTransport<T>::processErrorCode(const boost::system::error_code& error) |
| 289 | { |
| 290 | NFD_LOG_FACE_TRACE(__func__); |
| 291 | |
| 292 | if (getState() == TransportState::CLOSING || |
| 293 | getState() == TransportState::FAILED || |
| 294 | getState() == TransportState::CLOSED || |
| 295 | error == boost::asio::error::operation_aborted || // when cancel() is called |
| 296 | error == boost::asio::error::shut_down) // after shutdown() is called |
| 297 | // transport is shutting down, ignore any errors |
| 298 | return; |
| 299 | |
Weiwei Liu | dcdf621 | 2016-08-31 14:34:22 -0700 | [diff] [blame] | 300 | handleError(error); |
| 301 | } |
| 302 | |
| 303 | template<class T> |
| 304 | void |
| 305 | StreamTransport<T>::handleError(const boost::system::error_code& error) |
| 306 | { |
Davide Pesavento | 68ab43d | 2017-07-02 13:37:35 -0400 | [diff] [blame] | 307 | if (error == boost::asio::error::eof) { |
| 308 | this->setState(TransportState::CLOSING); |
| 309 | } |
| 310 | else { |
Davide Pesavento | 1816d4b | 2017-07-02 12:20:48 -0400 | [diff] [blame] | 311 | NFD_LOG_FACE_ERROR("Send or receive operation failed: " << error.message()); |
Davide Pesavento | 68ab43d | 2017-07-02 13:37:35 -0400 | [diff] [blame] | 312 | this->setState(TransportState::FAILED); |
| 313 | } |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 314 | doClose(); |
| 315 | } |
| 316 | |
Weiwei Liu | dcdf621 | 2016-08-31 14:34:22 -0700 | [diff] [blame] | 317 | template<class T> |
| 318 | void |
| 319 | StreamTransport<T>::resetReceiveBuffer() |
| 320 | { |
| 321 | m_receiveBufferSize = 0; |
| 322 | } |
| 323 | |
| 324 | template<class T> |
| 325 | void |
| 326 | StreamTransport<T>::resetSendQueue() |
| 327 | { |
| 328 | std::queue<Block> emptyQueue; |
| 329 | std::swap(emptyQueue, m_sendQueue); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 330 | m_sendQueueBytes = 0; |
| 331 | } |
| 332 | |
| 333 | template<class T> |
| 334 | size_t |
| 335 | StreamTransport<T>::getSendQueueBytes() const |
| 336 | { |
| 337 | return m_sendQueueBytes; |
Weiwei Liu | dcdf621 | 2016-08-31 14:34:22 -0700 | [diff] [blame] | 338 | } |
| 339 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 340 | } // namespace nfd::face |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 341 | |
| 342 | #endif // NFD_DAEMON_FACE_STREAM_TRANSPORT_HPP |