LCOV - code coverage report
Current view: top level - asiolink - udp_endpoint.h (source / functions) Hit Total Coverage
Test: report.info Lines: 19 24 79.2 %
Date: 2012-05-15 Functions: 9 11 81.8 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 6 12 50.0 %

           Branch data     Line data    Source code
       1                 :            : // Copyright (C) 2011  Internet Systems Consortium, Inc. ("ISC")
       2                 :            : //
       3                 :            : // Permission to use, copy, modify, and/or distribute this software for any
       4                 :            : // purpose with or without fee is hereby granted, provided that the above
       5                 :            : // copyright notice and this permission notice appear in all copies.
       6                 :            : //
       7                 :            : // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
       8                 :            : // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
       9                 :            : // AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
      10                 :            : // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
      11                 :            : // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
      12                 :            : // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
      13                 :            : // PERFORMANCE OF THIS SOFTWARE.
      14                 :            : 
      15                 :            : #ifndef __UDP_ENDPOINT_H
      16                 :            : #define __UDP_ENDPOINT_H 1
      17                 :            : 
      18                 :            : #ifndef ASIO_HPP
      19                 :            : #error "asio.hpp must be included before including this, see asiolink.h as to why"
      20                 :            : #endif
      21                 :            : 
      22                 :            : #include <asiolink/io_endpoint.h>
      23                 :            : 
      24                 :            : namespace isc {
      25                 :            : namespace asiolink {
      26                 :            : 
      27                 :            : /// \brief The \c UDPEndpoint class is a concrete derived class of
      28                 :            : /// \c IOEndpoint that represents an endpoint of a UDP packet.
      29                 :            : ///
      30                 :            : /// Other notes about \c TCPEndpoint applies to this class, too.
      31                 :            : class UDPEndpoint : public IOEndpoint {
      32                 :            : public:
      33                 :            :     ///
      34                 :            :     /// \name Constructors and Destructor.
      35                 :            :     ///
      36                 :            :     //@{
      37                 :            : 
      38                 :            :     /// \brief Default Constructor
      39                 :            :     ///
      40                 :            :     /// Creates an internal endpoint.  This is expected to be set by some
      41                 :            :     /// external call.
      42                 :          2 :     UDPEndpoint() :
      43                 :            :         asio_endpoint_placeholder_(new asio::ip::udp::endpoint()),
      44         [ +  - ]:          2 :         asio_endpoint_(*asio_endpoint_placeholder_)
      45                 :          2 :     {}
      46                 :            : 
      47                 :            :     /// \brief Constructor from a pair of address and port.
      48                 :            :     ///
      49                 :            :     /// \param address The IP address of the endpoint.
      50                 :            :     /// \param port The UDP port number of the endpoint.
      51                 :         76 :     UDPEndpoint(const IOAddress& address, const unsigned short port) :
      52                 :            :         asio_endpoint_placeholder_(
      53                 :        233 :             new asio::ip::udp::endpoint(asio::ip::address::from_string(address.toText()),
      54                 :          0 :                               port)),
      55 [ +  - ][ +  - ]:        310 :         asio_endpoint_(*asio_endpoint_placeholder_)
         [ +  - ][ +  - ]
                 [ +  - ]
      56                 :         76 :     {}
      57                 :            : 
      58                 :            :     /// \brief Constructor from an ASIO UDP endpoint.
      59                 :            :     ///
      60                 :            :     /// This constructor is designed to be an efficient wrapper for the
      61                 :            :     /// corresponding ASIO class, \c udp::endpoint.
      62                 :            :     ///
      63                 :            :     /// \param asio_endpoint The ASIO representation of the UDP endpoint.
      64                 :            :     UDPEndpoint(asio::ip::udp::endpoint& asio_endpoint) :
      65                 :         42 :         asio_endpoint_placeholder_(NULL), asio_endpoint_(asio_endpoint)
      66                 :            :     {}
      67                 :            : 
      68                 :            :     /// \brief Constructor from an ASIO UDP endpoint.
      69                 :            :     ///
      70                 :            :     /// This constructor is designed to be an efficient wrapper for the
      71                 :            :     /// corresponding ASIO class, \c udp::endpoint.
      72                 :            :     ///
      73                 :            :     /// \param asio_endpoint The ASIO representation of the TCP endpoint.
      74                 :            :     UDPEndpoint(const asio::ip::udp::endpoint& asio_endpoint) :
      75                 :            :         asio_endpoint_placeholder_(new asio::ip::udp::endpoint(asio_endpoint)),
      76                 :            :         asio_endpoint_(*asio_endpoint_placeholder_)
      77                 :            :     {}
      78                 :            : 
      79                 :            :     /// \brief The destructor.
      80                 :        683 :     virtual ~UDPEndpoint() { delete asio_endpoint_placeholder_; }
      81                 :            :     //@}
      82                 :            : 
      83                 :        131 :     virtual IOAddress getAddress() const {
      84                 :        131 :         return (asio_endpoint_.address());
      85                 :            :     }
      86                 :            : 
      87                 :         34 :     virtual const struct sockaddr& getSockAddr() const {
      88                 :         34 :         return (*asio_endpoint_.data());
      89                 :            :     }
      90                 :            : 
      91                 :        309 :     virtual uint16_t getPort() const {
      92                 :        309 :         return (asio_endpoint_.port());
      93                 :            :     }
      94                 :            : 
      95                 :        574 :     virtual short getProtocol() const {
      96                 :        574 :         return (asio_endpoint_.protocol().protocol());
      97                 :            :     }
      98                 :            : 
      99                 :        170 :     virtual short getFamily() const {
     100                 :        170 :         return (asio_endpoint_.protocol().family());
     101                 :            :     }
     102                 :            : 
     103                 :            :     // This is not part of the exosed IOEndpoint API but allows
     104                 :            :     // direct access to the ASIO implementation of the endpoint
     105                 :          0 :     inline const asio::ip::udp::endpoint& getASIOEndpoint() const {
     106                 :          0 :         return (asio_endpoint_);
     107                 :            :     }
     108                 :          0 :     inline asio::ip::udp::endpoint& getASIOEndpoint() {
     109                 :          0 :         return (asio_endpoint_);
     110                 :            :     }
     111                 :            : 
     112                 :            : private:
     113                 :            :     asio::ip::udp::endpoint* asio_endpoint_placeholder_;
     114                 :            :     asio::ip::udp::endpoint& asio_endpoint_;
     115                 :            : };
     116                 :            : 
     117                 :            : } // namespace asiolink
     118                 :            : } // namespace isc
     119                 :            : #endif // __UDP_ENDPOINT_H
     120                 :            : 
     121                 :            : // Local Variables:
     122                 :            : // mode: c++
     123                 :            : // End:

Generated by: LCOV version 1.9