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 | |
Davide Pesavento | d8d4d98 | 2014-03-21 18:47:58 +0100 | [diff] [blame] | 13 | UdpFace::UdpFace(const shared_ptr<UdpFace::protocol::socket>& socket, bool isOnDemand) |
| 14 | : DatagramFace<protocol>(FaceUri(socket->remote_endpoint()), socket, isOnDemand) |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 15 | { |
| 16 | } |
| 17 | |
| 18 | void |
| 19 | UdpFace::handleFirstReceive(const uint8_t* buffer, |
| 20 | std::size_t nBytesReceived, |
| 21 | const boost::system::error_code& error) |
| 22 | { |
Davide Pesavento | d8d4d98 | 2014-03-21 18:47:58 +0100 | [diff] [blame] | 23 | NFD_LOG_TRACE("handleFirstReceive"); |
| 24 | |
| 25 | // Checking if the received message size is too big. |
| 26 | // This check is redundant, since in the actual implementation |
| 27 | // a packet cannot be larger than MAX_NDN_PACKET_SIZE. |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 28 | if (!error && (nBytesReceived > MAX_NDN_PACKET_SIZE)) |
| 29 | { |
| 30 | NFD_LOG_WARN("[id:" << this->getId() |
| 31 | << ",endpoint:" << m_socket->local_endpoint() |
| 32 | << "] Received message too big. Maximum size is " |
| 33 | << MAX_NDN_PACKET_SIZE ); |
| 34 | return; |
| 35 | } |
Davide Pesavento | d8d4d98 | 2014-03-21 18:47:58 +0100 | [diff] [blame] | 36 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 37 | receiveDatagram(buffer, nBytesReceived, error); |
| 38 | } |
| 39 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 40 | } // namespace nfd |