blob: 1a4eb9c37e882483247f61db3d23e8b79c7289d9 [file] [log] [blame]
Giulio Grassi624f6c62014-02-18 19:42:14 +01001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (C) 2014 Named Data Networking Project
4 * See COPYING for copyright and distribution information.
5 */
6
7#include "udp-face.hpp"
8
9namespace nfd {
10
11NFD_LOG_INCLASS_TEMPLATE_SPECIALIZATION_DEFINE(DatagramFace, UdpFace::protocol, "UdpFace");
12
Davide Pesaventod8d4d982014-03-21 18:47:58 +010013UdpFace::UdpFace(const shared_ptr<UdpFace::protocol::socket>& socket, bool isOnDemand)
Junxiao Shi79494162014-04-02 18:25:11 -070014 : DatagramFace<protocol>(FaceUri(socket->remote_endpoint()),
15 FaceUri(socket->local_endpoint()),
16 socket, isOnDemand)
Giulio Grassi624f6c62014-02-18 19:42:14 +010017{
18}
19
20void
21UdpFace::handleFirstReceive(const uint8_t* buffer,
22 std::size_t nBytesReceived,
23 const boost::system::error_code& error)
24{
Davide Pesaventod8d4d982014-03-21 18:47:58 +010025 NFD_LOG_TRACE("handleFirstReceive");
26
27 // Checking if the received message size is too big.
28 // This check is redundant, since in the actual implementation
29 // a packet cannot be larger than MAX_NDN_PACKET_SIZE.
Giulio Grassi624f6c62014-02-18 19:42:14 +010030 if (!error && (nBytesReceived > MAX_NDN_PACKET_SIZE))
31 {
32 NFD_LOG_WARN("[id:" << this->getId()
33 << ",endpoint:" << m_socket->local_endpoint()
34 << "] Received message too big. Maximum size is "
35 << MAX_NDN_PACKET_SIZE );
36 return;
37 }
Davide Pesaventod8d4d982014-03-21 18:47:58 +010038
Giulio Grassi624f6c62014-02-18 19:42:14 +010039 receiveDatagram(buffer, nBytesReceived, error);
40}
41
Giulio Grassi624f6c62014-02-18 19:42:14 +010042} // namespace nfd