blob: e719da3c1fbe6bbc8c51928427d465fefc40f006 [file] [log] [blame]
Alexander Afanasyeva9034b02014-01-26 18:32:02 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi08d07a72014-06-09 23:17:57 -07003 * Copyright (c) 2014, Regents of the University of California,
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
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 *
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/>.
Junxiao Shi5dd26c32014-07-20 23:15:14 -070024 */
Alexander Afanasyeva9034b02014-01-26 18:32:02 -080025
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070026#ifndef NFD_DAEMON_FACE_STREAM_FACE_HPP
27#define NFD_DAEMON_FACE_STREAM_FACE_HPP
Alexander Afanasyeva9034b02014-01-26 18:32:02 -080028
29#include "face.hpp"
Alexander Afanasyevbd220a02014-02-20 00:29:56 -080030#include "local-face.hpp"
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -060031#include "core/logger.hpp"
Alexander Afanasyeva9034b02014-01-26 18:32:02 -080032
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080033namespace nfd {
Alexander Afanasyeva9034b02014-01-26 18:32:02 -080034
Alexander Afanasyevbd220a02014-02-20 00:29:56 -080035// forward declaration
36template<class T, class U, class V> struct StreamFaceSenderImpl;
37
38template<class Protocol, class FaceBase = Face>
39class StreamFace : public FaceBase
Alexander Afanasyeva9034b02014-01-26 18:32:02 -080040{
41public:
Alexander Afanasyevbd220a02014-02-20 00:29:56 -080042 typedef Protocol protocol;
Alexander Afanasyeva9034b02014-01-26 18:32:02 -080043
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -080044 /**
45 * \brief Create instance of StreamFace
46 */
Junxiao Shi79494162014-04-02 18:25:11 -070047 StreamFace(const FaceUri& remoteUri, const FaceUri& localUri,
Alexander Afanasyev355c0662014-03-20 18:08:17 -070048 const shared_ptr<typename protocol::socket>& socket,
49 bool isOnDemand);
Alexander Afanasyevd32cb962014-01-28 12:43:47 -080050
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -080051 virtual
52 ~StreamFace();
53
54 // from Face
55 virtual void
56 sendInterest(const Interest& interest);
57
58 virtual void
59 sendData(const Data& data);
60
61 virtual void
62 close();
Alexander Afanasyev93ce75e2014-02-18 19:45:34 -080063
Alexander Afanasyevd32cb962014-01-28 12:43:47 -080064protected:
65 void
Alexander Afanasyevbd220a02014-02-20 00:29:56 -080066 processErrorCode(const boost::system::error_code& error);
67
68 void
Alexander Afanasyeve5966b72014-07-20 23:39:50 -070069 sendFromQueue();
70
Alexander Afanasyevbd220a02014-02-20 00:29:56 -080071 void
Alexander Afanasyevd32cb962014-01-28 12:43:47 -080072 handleSend(const boost::system::error_code& error,
Junxiao Shi5dd26c32014-07-20 23:15:14 -070073 size_t nBytesSent);
Alexander Afanasyevd32cb962014-01-28 12:43:47 -080074
75 void
76 handleReceive(const boost::system::error_code& error,
Junxiao Shi5dd26c32014-07-20 23:15:14 -070077 size_t nBytesReceived);
Alexander Afanasyevd32cb962014-01-28 12:43:47 -080078
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -080079 void
Davide Pesavento3f5655f2014-08-30 21:38:59 +020080 shutdownSocket();
Davide Pesaventoba558e72014-02-17 18:38:19 +010081
82 void
Davide Pesavento3f5655f2014-08-30 21:38:59 +020083 deferredClose(const shared_ptr<Face>& face);
Davide Pesaventoba558e72014-02-17 18:38:19 +010084
Alexander Afanasyevd32cb962014-01-28 12:43:47 -080085protected:
86 shared_ptr<typename protocol::socket> m_socket;
Davide Pesaventoba558e72014-02-17 18:38:19 +010087
Alexander Afanasyevd32cb962014-01-28 12:43:47 -080088private:
Junxiao Shi39cd6332014-11-06 21:53:18 -070089 uint8_t m_inputBuffer[ndn::MAX_NDN_PACKET_SIZE];
Junxiao Shi5dd26c32014-07-20 23:15:14 -070090 size_t m_inputBufferSize;
Alexander Afanasyeve5966b72014-07-20 23:39:50 -070091 std::queue<Block> m_sendQueue;
Alexander Afanasyevbd220a02014-02-20 00:29:56 -080092
93 friend struct StreamFaceSenderImpl<Protocol, FaceBase, Interest>;
94 friend struct StreamFaceSenderImpl<Protocol, FaceBase, Data>;
95
Alexander Afanasyev3958b012014-01-31 15:06:13 -080096 NFD_LOG_INCLASS_DECLARE();
Alexander Afanasyeva9034b02014-01-26 18:32:02 -080097};
98
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -080099// All inherited classes must use
100// NFD_LOG_INCLASS_TEMPLATE_SPECIALIZATION_DEFINE(StreamFace, <specialization-parameter>, "Name");
Alexander Afanasyev3958b012014-01-31 15:06:13 -0800101
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800102
103/** \brief Class allowing validation of the StreamFace use
104 *
105 * For example, partial specialization based on boost::asio::ip::tcp should check
106 * that local endpoint is loopback
107 *
108 * @throws Face::Error if validation failed
109 */
110template<class Protocol, class U>
111struct StreamFaceValidator
112{
113 static void
114 validateSocket(typename Protocol::socket& socket)
115 {
116 }
117};
118
119
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +0000120template<class T, class FaceBase>
Alexander Afanasyevd32cb962014-01-28 12:43:47 -0800121inline
Junxiao Shi79494162014-04-02 18:25:11 -0700122StreamFace<T, FaceBase>::StreamFace(const FaceUri& remoteUri, const FaceUri& localUri,
123 const shared_ptr<typename StreamFace::protocol::socket>& socket,
124 bool isOnDemand)
125 : FaceBase(remoteUri, localUri)
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +0000126 , m_socket(socket)
Alexander Afanasyevb9f6e432014-02-14 20:52:49 -0800127 , m_inputBufferSize(0)
Alexander Afanasyevd32cb962014-01-28 12:43:47 -0800128{
Alexander Afanasyev355c0662014-03-20 18:08:17 -0700129 FaceBase::setOnDemand(isOnDemand);
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +0000130 StreamFaceValidator<T, FaceBase>::validateSocket(*socket);
Junxiao Shi39cd6332014-11-06 21:53:18 -0700131 m_socket->async_receive(boost::asio::buffer(m_inputBuffer, ndn::MAX_NDN_PACKET_SIZE), 0,
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +0000132 bind(&StreamFace<T, FaceBase>::handleReceive, this, _1, _2));
Alexander Afanasyevd32cb962014-01-28 12:43:47 -0800133}
134
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800135template<class T, class U>
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -0800136inline
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800137StreamFace<T, U>::~StreamFace()
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -0800138{
139}
140
Davide Pesavento3f5655f2014-08-30 21:38:59 +0200141
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800142template<class Protocol, class FaceBase, class Packet>
143struct StreamFaceSenderImpl
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -0800144{
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800145 static void
146 send(StreamFace<Protocol, FaceBase>& face, const Packet& packet)
147 {
Alexander Afanasyeve5966b72014-07-20 23:39:50 -0700148 bool wasQueueEmpty = face.m_sendQueue.empty();
149 face.m_sendQueue.push(packet.wireEncode());
150
151 if (wasQueueEmpty)
152 face.sendFromQueue();
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800153 }
154};
155
156// partial specialization (only classes can be partially specialized)
157template<class Protocol, class Packet>
158struct StreamFaceSenderImpl<Protocol, LocalFace, Packet>
159{
160 static void
161 send(StreamFace<Protocol, LocalFace>& face, const Packet& packet)
162 {
Alexander Afanasyeve5966b72014-07-20 23:39:50 -0700163 bool wasQueueEmpty = face.m_sendQueue.empty();
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800164
Alexander Afanasyeve5966b72014-07-20 23:39:50 -0700165 if (!face.isEmptyFilteredLocalControlHeader(packet.getLocalControlHeader()))
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800166 {
Alexander Afanasyeve5966b72014-07-20 23:39:50 -0700167 face.m_sendQueue.push(face.filterAndEncodeLocalControlHeader(packet));
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800168 }
Alexander Afanasyeve5966b72014-07-20 23:39:50 -0700169 face.m_sendQueue.push(packet.wireEncode());
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800170
Alexander Afanasyeve5966b72014-07-20 23:39:50 -0700171 if (wasQueueEmpty)
172 face.sendFromQueue();
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800173 }
174};
175
176
177template<class T, class U>
178inline void
179StreamFace<T, U>::sendInterest(const Interest& interest)
180{
Alexander Afanasyev7e698e62014-03-07 16:48:35 +0000181 this->onSendInterest(interest);
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800182 StreamFaceSenderImpl<T, U, Interest>::send(*this, interest);
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -0800183}
184
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800185template<class T, class U>
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -0800186inline void
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800187StreamFace<T, U>::sendData(const Data& data)
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -0800188{
Alexander Afanasyev7e698e62014-03-07 16:48:35 +0000189 this->onSendData(data);
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800190 StreamFaceSenderImpl<T, U, Data>::send(*this, data);
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -0800191}
192
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800193template<class T, class U>
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -0800194inline void
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800195StreamFace<T, U>::close()
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -0800196{
197 if (!m_socket->is_open())
198 return;
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800199
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -0800200 NFD_LOG_INFO("[id:" << this->getId()
Alexander Afanasyev29d1fab2014-07-07 19:27:16 -0700201 << ",uri:" << this->getRemoteUri()
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -0800202 << "] Close connection");
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -0800203
Davide Pesavento3f5655f2014-08-30 21:38:59 +0200204 shutdownSocket();
Junxiao Shi08d07a72014-06-09 23:17:57 -0700205 this->fail("Close connection");
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -0800206}
Alexander Afanasyevd32cb962014-01-28 12:43:47 -0800207
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800208template<class T, class U>
Alexander Afanasyevd32cb962014-01-28 12:43:47 -0800209inline void
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800210StreamFace<T, U>::processErrorCode(const boost::system::error_code& error)
Alexander Afanasyevd32cb962014-01-28 12:43:47 -0800211{
Davide Pesavento3f5655f2014-08-30 21:38:59 +0200212 if (error == boost::asio::error::operation_aborted || // when cancel() is called
213 error == boost::asio::error::shut_down) // after shutdown() is called
Alexander Afanasyevd32cb962014-01-28 12:43:47 -0800214 return;
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800215
216 if (!m_socket->is_open())
217 {
Junxiao Shi08d07a72014-06-09 23:17:57 -0700218 this->fail("Connection closed");
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800219 return;
220 }
221
222 if (error == boost::asio::error::eof)
223 {
224 NFD_LOG_INFO("[id:" << this->getId()
Alexander Afanasyev29d1fab2014-07-07 19:27:16 -0700225 << ",uri:" << this->getRemoteUri()
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800226 << "] Connection closed");
227 }
228 else
229 {
230 NFD_LOG_WARN("[id:" << this->getId()
Alexander Afanasyev29d1fab2014-07-07 19:27:16 -0700231 << ",uri:" << this->getRemoteUri()
Davide Pesavento3f5655f2014-08-30 21:38:59 +0200232 << "] Send or receive operation failed, closing face: "
233 << error.message());
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800234 }
235
Davide Pesavento3f5655f2014-08-30 21:38:59 +0200236 shutdownSocket();
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800237
238 if (error == boost::asio::error::eof)
239 {
Junxiao Shi08d07a72014-06-09 23:17:57 -0700240 this->fail("Connection closed");
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800241 }
242 else
243 {
Davide Pesavento3f5655f2014-08-30 21:38:59 +0200244 this->fail("Send or receive operation failed, closing face: " + error.message());
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800245 }
246}
247
Davide Pesavento3f5655f2014-08-30 21:38:59 +0200248template<class T, class U>
249inline void
250StreamFace<T, U>::sendFromQueue()
251{
252 const Block& block = this->m_sendQueue.front();
253 boost::asio::async_write(*this->m_socket, boost::asio::buffer(block),
254 bind(&StreamFace<T, U>::handleSend, this, _1, _2));
255}
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800256
257template<class T, class U>
258inline void
259StreamFace<T, U>::handleSend(const boost::system::error_code& error,
Junxiao Shi5dd26c32014-07-20 23:15:14 -0700260 size_t nBytesSent)
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800261{
262 if (error)
263 return processErrorCode(error);
Alexander Afanasyevd32cb962014-01-28 12:43:47 -0800264
Alexander Afanasyeve5966b72014-07-20 23:39:50 -0700265 BOOST_ASSERT(!m_sendQueue.empty());
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800266
267 NFD_LOG_TRACE("[id:" << this->getId()
Alexander Afanasyev29d1fab2014-07-07 19:27:16 -0700268 << ",uri:" << this->getRemoteUri()
Junxiao Shi5dd26c32014-07-20 23:15:14 -0700269 << "] Successfully sent: " << nBytesSent << " bytes");
270 this->getMutableCounters().getNOutBytes() += nBytesSent;
Alexander Afanasyeve5966b72014-07-20 23:39:50 -0700271
272 m_sendQueue.pop();
273 if (!m_sendQueue.empty())
274 sendFromQueue();
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800275}
276
277template<class T, class U>
278inline void
279StreamFace<T, U>::handleReceive(const boost::system::error_code& error,
Junxiao Shi5dd26c32014-07-20 23:15:14 -0700280 size_t nBytesReceived)
Alexander Afanasyevd32cb962014-01-28 12:43:47 -0800281{
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800282 if (error)
283 return processErrorCode(error);
Alexander Afanasyevd32cb962014-01-28 12:43:47 -0800284
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -0800285 NFD_LOG_TRACE("[id:" << this->getId()
Alexander Afanasyev29d1fab2014-07-07 19:27:16 -0700286 << ",uri:" << this->getRemoteUri()
Alexander Afanasyeve5966b72014-07-20 23:39:50 -0700287 << "] Received: " << nBytesReceived << " bytes");
Junxiao Shi5dd26c32014-07-20 23:15:14 -0700288 this->getMutableCounters().getNInBytes() += nBytesReceived;
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -0800289
Alexander Afanasyeve5966b72014-07-20 23:39:50 -0700290 m_inputBufferSize += nBytesReceived;
Alexander Afanasyevd32cb962014-01-28 12:43:47 -0800291
Junxiao Shi5dd26c32014-07-20 23:15:14 -0700292 size_t offset = 0;
Alexander Afanasyevd32cb962014-01-28 12:43:47 -0800293
Alexander Afanasyev5a8d8d82014-03-21 14:08:41 -0700294 bool isOk = true;
295 Block element;
Junxiao Shi5dd26c32014-07-20 23:15:14 -0700296 while (m_inputBufferSize - offset > 0)
Alexander Afanasyev5a8d8d82014-03-21 14:08:41 -0700297 {
298 isOk = Block::fromBuffer(m_inputBuffer + offset, m_inputBufferSize - offset, element);
299 if (!isOk)
300 break;
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800301
Alexander Afanasyev5a8d8d82014-03-21 14:08:41 -0700302 offset += element.size();
Davide Pesaventoba558e72014-02-17 18:38:19 +0100303
Alexander Afanasyev5a8d8d82014-03-21 14:08:41 -0700304 BOOST_ASSERT(offset <= m_inputBufferSize);
305
306 if (!this->decodeAndDispatchInput(element))
307 {
308 NFD_LOG_WARN("[id:" << this->getId()
Alexander Afanasyev29d1fab2014-07-07 19:27:16 -0700309 << ",uri:" << this->getRemoteUri()
Alexander Afanasyev5a8d8d82014-03-21 14:08:41 -0700310 << "] Received unrecognized block of type ["
311 << element.type() << "]");
312 // ignore unknown packet and proceed
313 }
314 }
Junxiao Shi39cd6332014-11-06 21:53:18 -0700315 if (!isOk && m_inputBufferSize == ndn::MAX_NDN_PACKET_SIZE && offset == 0)
Alexander Afanasyev5a8d8d82014-03-21 14:08:41 -0700316 {
317 NFD_LOG_WARN("[id:" << this->getId()
Alexander Afanasyev29d1fab2014-07-07 19:27:16 -0700318 << ",uri:" << this->getRemoteUri()
Davide Pesavento3f5655f2014-08-30 21:38:59 +0200319 << "] Failed to parse incoming packet or packet too large to process, "
Alexander Afanasyev5a8d8d82014-03-21 14:08:41 -0700320 << "closing down the face");
Davide Pesavento3f5655f2014-08-30 21:38:59 +0200321 shutdownSocket();
322 this->fail("Failed to parse incoming packet or packet too large to process, "
323 "closing down the face");
Alexander Afanasyev5a8d8d82014-03-21 14:08:41 -0700324 return;
325 }
Alexander Afanasyevd32cb962014-01-28 12:43:47 -0800326
327 if (offset > 0)
328 {
329 if (offset != m_inputBufferSize)
330 {
331 std::copy(m_inputBuffer + offset, m_inputBuffer + m_inputBufferSize,
332 m_inputBuffer);
333 m_inputBufferSize -= offset;
334 }
335 else
336 {
337 m_inputBufferSize = 0;
338 }
339 }
340
341 m_socket->async_receive(boost::asio::buffer(m_inputBuffer + m_inputBufferSize,
Junxiao Shi39cd6332014-11-06 21:53:18 -0700342 ndn::MAX_NDN_PACKET_SIZE - m_inputBufferSize), 0,
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800343 bind(&StreamFace<T, U>::handleReceive, this, _1, _2));
Alexander Afanasyevd32cb962014-01-28 12:43:47 -0800344}
345
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800346template<class T, class U>
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -0800347inline void
Davide Pesavento3f5655f2014-08-30 21:38:59 +0200348StreamFace<T, U>::shutdownSocket()
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -0800349{
Davide Pesavento3f5655f2014-08-30 21:38:59 +0200350 // Cancel all outstanding operations and shutdown the socket
351 // so that no further sends or receives are possible.
352 // Use the non-throwing variants and ignore errors, if any.
353 boost::system::error_code error;
354 m_socket->cancel(error);
355 m_socket->shutdown(protocol::socket::shutdown_both, error);
356
357 boost::asio::io_service& io = m_socket->get_io_service();
358 // ensure that the Face object is alive at least until all pending
359 // handlers are dispatched
360 io.post(bind(&StreamFace<T, U>::deferredClose, this, this->shared_from_this()));
361
362 // Some bug or feature of Boost.Asio (see http://redmine.named-data.net/issues/1856):
363 //
364 // When shutdownSocket is called from within a socket event (e.g., from handleReceive),
365 // m_socket->shutdown() does not trigger the cancellation of the handleSend callback.
366 // Instead, handleSend is invoked as nothing bad happened.
367 //
368 // In order to prevent the assertion in handleSend from failing, we clear the queue
369 // and close the socket in deferredClose, i.e., after all callbacks scheduled up to
370 // this point have been executed. If more send operations are scheduled after this
371 // point, they will fail because the socket has been shutdown, and their callbacks
372 // will be invoked with error code == asio::error::shut_down.
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -0800373}
374
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800375template<class T, class U>
Davide Pesaventoba558e72014-02-17 18:38:19 +0100376inline void
Davide Pesavento3f5655f2014-08-30 21:38:59 +0200377StreamFace<T, U>::deferredClose(const shared_ptr<Face>& face)
Davide Pesaventoba558e72014-02-17 18:38:19 +0100378{
Davide Pesavento3f5655f2014-08-30 21:38:59 +0200379 NFD_LOG_DEBUG("[id:" << this->getId()
380 << ",uri:" << this->getRemoteUri()
381 << "] Clearing send queue");
Alexander Afanasyeve5966b72014-07-20 23:39:50 -0700382
383 // clear send queue
384 std::queue<Block> emptyQueue;
385 std::swap(emptyQueue, m_sendQueue);
Davide Pesavento3f5655f2014-08-30 21:38:59 +0200386
387 // use the non-throwing variant and ignore errors, if any
388 boost::system::error_code error;
389 m_socket->close(error);
Davide Pesaventoba558e72014-02-17 18:38:19 +0100390}
Alexander Afanasyevd32cb962014-01-28 12:43:47 -0800391
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800392} // namespace nfd
Alexander Afanasyeva9034b02014-01-26 18:32:02 -0800393
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700394#endif // NFD_DAEMON_FACE_STREAM_FACE_HPP