LCOV - code coverage report
Current view: top level - xfr - xfrout_client.cc (source / functions) Hit Total Coverage
Test: report.info Lines: 15 30 50.0 %
Date: 2012-05-15 Functions: 6 9 66.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 14 56 25.0 %

           Branch data     Line data    Source code
       1                 :            : // Copyright (C) 2010  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 <cstdlib>
      16                 :            : #include <cstring>
      17                 :            : #include <iostream>
      18                 :            : 
      19                 :            : // for some IPC/network system calls in asio/detail/pipe_select_interrupter.hpp
      20                 :            : #include <unistd.h>
      21                 :            : #include <asio.hpp>
      22                 :            : 
      23                 :            : #include <util/io/fd_share.h>
      24                 :            : #include <xfr/xfrout_client.h>
      25                 :            : 
      26                 :            : using namespace std;
      27                 :            : using namespace isc::util::io;
      28                 :            : using asio::local::stream_protocol;
      29                 :            : 
      30                 :            : namespace isc {
      31                 :            : namespace xfr {
      32                 :            : 
      33         [ +  - ]:          2 : struct XfroutClientImpl {
      34                 :            :     XfroutClientImpl(const string& file);
      35                 :            :     const std::string file_path_;
      36                 :            :     asio::io_service io_service_;
      37                 :            :     // The socket used to communicate with the xfrout server.
      38                 :            :     stream_protocol::socket socket_;
      39                 :            : };
      40                 :            : 
      41                 :          2 : XfroutClientImpl::XfroutClientImpl(const string& file) :
      42                 :          2 :     file_path_(file), socket_(io_service_)
      43                 :          2 : {}
      44                 :            : 
      45                 :          2 : XfroutClient::XfroutClient(const string& file) :
      46 [ +  - ][ +  - ]:          2 :     impl_(new XfroutClientImpl(file))
      47                 :          2 : {}
      48                 :            : 
      49                 :          2 : XfroutClient::~XfroutClient() {
      50         [ +  - ]:          4 :     delete impl_;
      51                 :          2 : }
      52                 :            : 
      53                 :            : void
      54                 :          2 : XfroutClient::connect() {
      55                 :            :     try {
      56         [ -  + ]:          1 :         impl_->socket_.connect(stream_protocol::endpoint(impl_->file_path_));
      57         [ -  + ]:          4 :     } catch (const asio::system_error& err) {
      58 [ -  + ][ -  + ]:          4 :         isc_throw(XfroutError, "socket connect failed for " <<
         [ -  + ][ -  + ]
         [ -  + ][ -  + ]
      59                 :            :                   impl_->file_path_ << ": " << err.what());
      60                 :            :     }
      61                 :          0 : }
      62                 :            : 
      63                 :            : void
      64                 :          0 : XfroutClient::disconnect() {
      65                 :            :     asio::error_code err;
      66                 :          0 :     impl_->socket_.close(err);
      67         [ #  # ]:          0 :     if (err) {
      68 [ #  # ][ #  # ]:          0 :         isc_throw(XfroutError, "close socket failed: " << err.message());
         [ #  # ][ #  # ]
      69                 :            :     }
      70                 :          0 : }
      71                 :            : 
      72                 :            : int
      73                 :          0 : XfroutClient::sendXfroutRequestInfo(const int tcp_sock,
      74                 :            :                                     const void* const msg_data,
      75                 :            :                                     const uint16_t msg_len)
      76                 :            : {
      77         [ #  # ]:          0 :     if (send_fd(impl_->socket_.native(), tcp_sock) < 0) {
      78 [ #  # ][ #  # ]:          0 :         isc_throw(XfroutError,
      79                 :            :                   "Failed to send the socket file descriptor "
      80                 :            :                   "to xfrout module");
      81                 :            :     }
      82                 :            : 
      83                 :            :     // TODO: this shouldn't be blocking send, even though it's unlikely to
      84                 :            :     // block.
      85                 :            :     // converting the 16-bit word to network byte order.
      86                 :          0 :     const uint8_t lenbuf[2] = { msg_len >> 8, msg_len & 0xff };
      87         [ #  # ]:          0 :     if (send(impl_->socket_.native(), lenbuf, sizeof(lenbuf), 0) !=
      88                 :            :         sizeof(lenbuf)) {
      89 [ #  # ][ #  # ]:          0 :         isc_throw(XfroutError,
      90                 :            :                   "failed to send XFR request length to xfrout module");
      91                 :            :     }
      92         [ #  # ]:          0 :     if (send(impl_->socket_.native(), msg_data, msg_len, 0) != msg_len) {
      93 [ #  # ][ #  # ]:          0 :         isc_throw(XfroutError,
      94                 :            :                   "failed to send XFR request data to xfrout module");
      95                 :            :     }
      96                 :            : 
      97                 :          0 :     return (0);
      98                 :            : }
      99                 :            : 
     100                 :            : } // End for xfr
     101 [ +  - ][ +  - ]:          3 : } // End for isc
     102                 :            : 

Generated by: LCOV version 1.9