LCOV - code coverage report
Current view: top level - home/h/core/forks/m4-libzmq/src - address.cpp (source / functions) Hit Total Coverage
Test: zeromq-4.2.0 Code Coverage Lines: 30 31 96.8 %
Date: 2016-05-09 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :     Copyright (c) 2007-2016 Contributors as noted in the AUTHORS file
       3             : 
       4             :     This file is part of libzmq, the ZeroMQ core engine in C++.
       5             : 
       6             :     libzmq is free software; you can redistribute it and/or modify it under
       7             :     the terms of the GNU Lesser General Public License (LGPL) as published
       8             :     by the Free Software Foundation; either version 3 of the License, or
       9             :     (at your option) any later version.
      10             : 
      11             :     As a special exception, the Contributors give you permission to link
      12             :     this library with independent modules to produce an executable,
      13             :     regardless of the license terms of these independent modules, and to
      14             :     copy and distribute the resulting executable under terms of your choice,
      15             :     provided that you also meet, for each linked independent module, the
      16             :     terms and conditions of the license of that module. An independent
      17             :     module is a module which is not derived from or based on this library.
      18             :     If you modify this library, you must extend this exception to your
      19             :     version of the library.
      20             : 
      21             :     libzmq is distributed in the hope that it will be useful, but WITHOUT
      22             :     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
      23             :     FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
      24             :     License for more details.
      25             : 
      26             :     You should have received a copy of the GNU Lesser General Public License
      27             :     along with this program.  If not, see <http://www.gnu.org/licenses/>.
      28             : */
      29             : 
      30             : #include "precompiled.hpp"
      31             : #include "macros.hpp"
      32             : #include "platform.hpp"
      33             : #include "address.hpp"
      34             : #include "ctx.hpp"
      35             : #include "err.hpp"
      36             : #include "tcp_address.hpp"
      37             : #include "udp_address.hpp"
      38             : #include "ipc_address.hpp"
      39             : #include "tipc_address.hpp"
      40             : 
      41             : #if defined ZMQ_HAVE_VMCI
      42             : #include "vmci_address.hpp"
      43             : #endif
      44             : 
      45             : #include <string>
      46             : #include <sstream>
      47             : 
      48        3756 : zmq::address_t::address_t (
      49             :     const std::string &protocol_, const std::string &address_, ctx_t *parent_)
      50             :     : protocol (protocol_),
      51             :       address (address_),
      52        3756 :       parent (parent_)
      53             : {
      54        3756 :     memset (&resolved, 0, sizeof resolved);
      55        3756 : }
      56             : 
      57       11266 : zmq::address_t::~address_t ()
      58             : {
      59        7512 :     if (protocol == "tcp") {
      60        3687 :         if (resolved.tcp_addr) {
      61        3671 :             LIBZMQ_DELETE(resolved.tcp_addr);
      62             :         }
      63             :     }
      64        7510 :     if (protocol == "udp") {
      65           6 :         if (resolved.udp_addr) {
      66           6 :             LIBZMQ_DELETE(resolved.udp_addr);
      67             :         }
      68             :     }
      69             : #if !defined ZMQ_HAVE_WINDOWS && !defined ZMQ_HAVE_OPENVMS
      70             :     else
      71        7496 :     if (protocol == "ipc") {
      72          63 :         if (resolved.ipc_addr) {
      73          63 :             LIBZMQ_DELETE(resolved.ipc_addr);
      74             :         }
      75             :     }
      76             : #endif
      77             : #if defined ZMQ_HAVE_TIPC
      78             :     else
      79             :     if (protocol == "tipc") {
      80             :         if (resolved.tipc_addr) {
      81             :             LIBZMQ_DELETE(resolved.tipc_addr);
      82             :         }
      83             :     }
      84             : #endif
      85             : #if defined ZMQ_HAVE_VMCI
      86             :     else
      87             :     if (protocol == "vmci") {
      88             :         if (resolved.vmci_addr) {
      89             :             LIBZMQ_DELETE(resolved.vmci_addr);
      90             :         }
      91             :     }
      92             : #endif
      93        3754 : }
      94             : 
      95        7685 : int zmq::address_t::to_string (std::string &addr_) const
      96             : {
      97       15368 :     if (protocol == "tcp") {
      98        7549 :         if (resolved.tcp_addr)
      99         199 :             return resolved.tcp_addr->to_string (addr_);
     100             :     }
     101       14971 :     if (protocol == "udp") {
     102           6 :         if (resolved.udp_addr)
     103           6 :             return resolved.udp_addr->to_string (addr_);
     104             :     }
     105             : #if !defined ZMQ_HAVE_WINDOWS && !defined ZMQ_HAVE_OPENVMS
     106             :     else
     107       14963 :     if (protocol == "ipc") {
     108         128 :         if (resolved.ipc_addr)
     109         128 :             return resolved.ipc_addr->to_string (addr_);
     110             :     }
     111             : #endif
     112             : #if defined ZMQ_HAVE_TIPC
     113             :     else
     114             :     if (protocol == "tipc") {
     115             :         if (resolved.tipc_addr)
     116             :             return resolved.tipc_addr->to_string (addr_);
     117             :     }
     118             : #endif
     119             : #if defined ZMQ_HAVE_VMCI
     120             :     else
     121             :     if (protocol == "vmci") {
     122             :         if (resolved.vmci_addr)
     123             :             return resolved.vmci_addr->to_string (addr_);
     124             :     }
     125             : #endif
     126             : 
     127       22062 :     if (!protocol.empty () && !address.empty ()) {
     128        7354 :         std::stringstream s;
     129       14707 :         s << protocol << "://" << address;
     130        7356 :         addr_ = s.str ();
     131        7356 :         return 0;
     132             :     }
     133             :     addr_.clear ();
     134           0 :     return -1;
     135             : }

Generated by: LCOV version 1.10