Example #1
0
void test_log()
{
    hc_set_default_log_fun(HC_LOG_TRACE_LVL);
    HC_LOG_TRACE("");

    HC_LOG_DEBUG("HC_LOG_DEBUG");
    HC_LOG_INFO("HC_LOG_INFO");
    HC_LOG_WARN("HC_LOG_WARN");
    HC_LOG_ERROR("HC_LOG_ERROR");
    HC_LOG_FATAL("HC_LOG_FATAL");
}
Example #2
0
bool if_prop::refresh_network_interfaces(){
     HC_LOG_TRACE("");

     //clean
     if(is_getaddrs_valid()){
          freeifaddrs(m_if_addrs);
     }

     m_if_map.clear();

     //create
     if(getifaddrs(&m_if_addrs) < 0){
          HC_LOG_ERROR("getifaddrs failed! Error: " << strerror(errno) );
          return false;
     }

     struct ifaddrs* ifEntry=NULL;
     for(ifEntry=m_if_addrs; ifEntry!=NULL; ifEntry=ifEntry->ifa_next) {
          if(ifEntry->ifa_addr->sa_data == NULL) {
               continue;
          }


          if(ifEntry->ifa_addr->sa_family==AF_INET) {
               if_prop_map::iterator iter = m_if_map.find(ifEntry->ifa_name);
               if(iter != m_if_map.end()){ //existing interface
                    if(iter->second.ip4_addr != NULL){
                        HC_LOG_WARN("more than one ipv4 address for one interface configurated! used:" << addr_storage(*(iter->second.ip4_addr->ifa_addr)) << "; don't used:" << addr_storage(*(ifEntry->ifa_addr)) << ";");
                        //return false;
                    }else{
                         iter->second.ip4_addr = ifEntry;
                    }
               }else{ //new interface
                    m_if_map.insert(if_prop_pair(ifEntry->ifa_name, ipv4_6_pair(ifEntry,list<const struct ifaddrs*>())));
               }
          } else if(ifEntry->ifa_addr->sa_family==AF_INET6) {
               if_prop_map::iterator iter = m_if_map.find(ifEntry->ifa_name);
               if(iter != m_if_map.end()){ //existing interface
                    list<const struct ifaddrs*>* l = &iter->second.ip6_addr;
                    l->push_back(ifEntry);
               }else{ //new interface
                    list<const struct ifaddrs*> l;
                    l.push_back(ifEntry);
                    m_if_map.insert(if_prop_pair(ifEntry->ifa_name, ipv4_6_pair(NULL,l)));
               }
          } else {
               //It isn't IPv4 or IPv6
               continue;
          }

     }
     return true;
}
Example #3
0
void proxy_instance::registrate_if(int if_index){
    HC_LOG_TRACE("");

    vif_map::iterator it_vif_map;
    if((it_vif_map = m_vif_map.find(if_index))== m_vif_map.end()){
        HC_LOG_ERROR("failed to find vif from if_index:" << if_index);
        return;
    }
    int vif = it_vif_map->second;

    //##-- routing --##
    m_routing.add_vif( if_index, vif);

    //##-- receiver --##
    m_receiver->registrate_interface(if_index, vif, this);

    if(if_index != m_upstream){

        //##-- sender --##
        //join all_router_addr at all downstreams
        if(m_addr_family == AF_INET){
            addr_storage mc_router_addr(IPV4_ALL_IGMP_ROUTERS_ADDR);
            if(!m_sender->send_report(if_index, mc_router_addr)){
                HC_LOG_ERROR("failed to join: ==> " << IPV4_ALL_IGMP_ROUTERS_ADDR);
            }
        }else if(m_addr_family == AF_INET6){
            addr_storage mc_router_addr(IPV6_ALL_LINK_LOCAL_ROUTER);
            if(!m_sender->send_report(if_index, mc_router_addr )){
                HC_LOG_ERROR("failed to join: ==> " << mc_router_addr);
            }

            mc_router_addr= IPV6_ALL_SITE_LOCAL_ROUTER;
            if(!m_sender->send_report(if_index, mc_router_addr )){
                HC_LOG_ERROR("failed to join: ==> " << mc_router_addr);
            }

            HC_LOG_WARN("untesteted");
        }else{
            HC_LOG_ERROR("wrong addr_family: " << m_addr_family);
            return;
        }

        //send the first GQ
        if(!m_sender->send_general_query(if_index)){
            HC_LOG_ERROR("failed to send general to if_index: " << if_index);
            return;
        }
    }
}
Example #4
0
bool message_queue<T, Compare>::enqueue_loseable(const T& t)
{
    HC_LOG_TRACE("");

    {
        std::unique_lock<std::mutex> lock(m_global_lock);
        if (m_q.size() < m_size) {
            m_q.push(t);
        } else {
            HC_LOG_WARN("message_queue is full, failed to insert message");
            return false;
        }
    }
    cond_empty.notify_one();
    return true;
}