LCOV - code coverage report
Current view: top level - asiodns - dns_service.cc (source / functions) Hit Total Coverage
Test: report.info Lines: 28 29 96.6 %
Date: 2012-05-15 Functions: 11 11 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 22 44 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                 :            : #include <config.h>
      16                 :            : 
      17                 :            : #include <exceptions/exceptions.h>
      18                 :            : 
      19                 :            : #include <dns_service.h>
      20                 :            : 
      21                 :            : #include <asiolink/io_service.h>
      22                 :            : 
      23                 :            : #include <asio.hpp> // xxx_server.h requires this to be included first
      24                 :            : #include <tcp_server.h>
      25                 :            : #include <udp_server.h>
      26                 :            : #include <sync_udp_server.h>
      27                 :            : 
      28                 :            : #include <boost/foreach.hpp>
      29                 :            : 
      30                 :            : using namespace isc::asiolink;
      31                 :            : 
      32                 :            : namespace isc {
      33                 :            : namespace asiodns {
      34                 :            : 
      35                 :            : class DNSLookup;
      36                 :            : class DNSAnswer;
      37                 :            : 
      38                 :         44 : class DNSServiceImpl {
      39                 :            : public:
      40                 :            :     DNSServiceImpl(IOService& io_service, SimpleCallback* checkin,
      41                 :            :                    DNSLookup* lookup, DNSAnswer* answer) :
      42                 :            :             io_service_(io_service), checkin_(checkin), lookup_(lookup),
      43                 :         88 :             answer_(answer)
      44                 :            :     {}
      45                 :            : 
      46                 :            :     IOService& io_service_;
      47                 :            : 
      48                 :            :     typedef boost::shared_ptr<UDPServer> UDPServerPtr;
      49                 :            :     typedef boost::shared_ptr<SyncUDPServer> SyncUDPServerPtr;
      50                 :            :     typedef boost::shared_ptr<TCPServer> TCPServerPtr;
      51                 :            :     typedef boost::shared_ptr<DNSServer> DNSServerPtr;
      52                 :            :     std::vector<DNSServerPtr> servers_;
      53                 :            :     SimpleCallback* checkin_;
      54                 :            :     DNSLookup* lookup_;
      55                 :            :     DNSAnswer* answer_;
      56                 :            : 
      57                 :        111 :     template<class Ptr, class Server> void addServerFromFD(int fd, int af) {
      58                 :            :         Ptr server(new Server(io_service_.get_io_service(), fd, af, checkin_,
      59 [ +  - ][ +  - ]:        111 :                               lookup_, answer_));
                 [ +  - ]
      60 [ +  - ][ +  - ]:        111 :         (*server)();
                 [ +  - ]
      61 [ +  - ][ +  - ]:        111 :         servers_.push_back(server);
                 [ +  - ]
      62                 :        111 :     }
      63                 :            : };
      64                 :            : 
      65                 :         44 : DNSService::DNSService(IOService& io_service, SimpleCallback* checkin,
      66                 :            :                        DNSLookup* lookup, DNSAnswer *answer) :
      67                 :            :     impl_(new DNSServiceImpl(io_service, checkin, lookup, answer)),
      68         [ +  - ]:         44 :     io_service_(io_service)
      69                 :            : {
      70                 :         44 : }
      71                 :            : 
      72                 :         82 : DNSService::~DNSService() {
      73         [ +  - ]:         88 :     delete impl_;
      74                 :         82 : }
      75                 :            : 
      76                 :         55 : void DNSService::addServerTCPFromFD(int fd, int af) {
      77                 :         55 :     impl_->addServerFromFD<DNSServiceImpl::TCPServerPtr, TCPServer>(fd, af);
      78                 :         55 : }
      79                 :            : 
      80                 :         57 : void DNSService::addServerUDPFromFD(int fd, int af, ServerFlag options) {
      81         [ +  + ]:         57 :     if ((~SERVER_DEFINED_FLAGS & static_cast<unsigned int>(options)) != 0) {
      82 [ +  - ][ +  - ]:          2 :         isc_throw(isc::InvalidParameter, "Invalid DNS/UDP server option: "
      83                 :            :                   << options);
      84                 :            :     }
      85         [ +  + ]:         56 :     if ((options & SERVER_SYNC_OK) != 0) {
      86                 :            :         impl_->addServerFromFD<DNSServiceImpl::SyncUDPServerPtr,
      87                 :          1 :             SyncUDPServer>(fd, af);
      88                 :            :     } else {
      89                 :            :         impl_->addServerFromFD<DNSServiceImpl::UDPServerPtr, UDPServer>(
      90                 :         55 :             fd, af);
      91                 :            :     }
      92                 :         56 : }
      93                 :            : 
      94                 :            : void
      95                 :          1 : DNSService::clearServers() {
      96 [ #  # ][ #  # ]:          1 :     BOOST_FOREACH(const DNSServiceImpl::DNSServerPtr& s, impl_->servers_) {
         [ +  - ][ +  - ]
                 [ -  + ]
      97                 :          0 :         s->stop();
      98                 :            :     }
      99                 :          1 :     impl_->servers_.clear();
     100                 :          1 : }
     101                 :            : 
     102                 :            : } // namespace asiodns
     103 [ +  - ][ +  - ]:          9 : } // namespace isc

Generated by: LCOV version 1.9