Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 1 | /* -*- 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 | |
| 9 | namespace nfd { |
| 10 | |
| 11 | NFD_LOG_INCLASS_TEMPLATE_SPECIALIZATION_DEFINE(DatagramFace, UdpFace::protocol, "UdpFace"); |
| 12 | |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 13 | UdpFace::UdpFace(const shared_ptr<UdpFace::protocol::socket>& socket, |
| 14 | bool isPermanent) |
| 15 | : DatagramFace<protocol>(FaceUri(socket->remote_endpoint()), |
| 16 | socket, |
| 17 | isPermanent) |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 18 | { |
| 19 | } |
| 20 | |
| 21 | void |
| 22 | UdpFace::handleFirstReceive(const uint8_t* buffer, |
| 23 | std::size_t nBytesReceived, |
| 24 | const boost::system::error_code& error) |
| 25 | { |
Alexander Afanasyev | 7e698e6 | 2014-03-07 16:48:35 +0000 | [diff] [blame] | 26 | NFD_LOG_DEBUG("handleFirstReceive"); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 27 | //checking if the received message size is too big. |
| 28 | //This check is redundant, since in the actual implementation a packet |
| 29 | //cannot be bigger than MAX_NDN_PACKET_SIZE |
| 30 | 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 | } |
| 38 | receiveDatagram(buffer, nBytesReceived, error); |
| 39 | } |
| 40 | |
| 41 | |
| 42 | } // namespace nfd |