示例#1
0
CALLR  CtxDns::_get_hostname()
{
    DnsCommon dns;

    if(__dnsssl->deque_host(_cliip, _hdr.asll(), dns))
    {
        LOGT(" found  host from dns[" << IP2STR(_cliip) << "]<="<< dns.hostname);
        if(dns.domainip==0)
        {
             _raddr = __db->dnsgetip(dns.hostname);
        }
        else
        {
            _raddr = SADDR_46(dns.domainip);
        }
        _raddr.set_port(_pconf->conport ? _pconf->conport : 80);
        _set_rhost(_raddr);
        LOGD(_cliip.c_str() << " --r/dns--> "<< _raddr.c_str() );
        return _host_connect(_r_socket);
    }
    else if(!_pconf->redirect.empty())
    {    //fallback
        _set_rhost(_pconf->toaddr, 0, 0);
        LOGD(_cliip.c_str() << " --r/cfg--> "<< _raddr.c_str() );
        return _host_connect(_r_socket);
    }
    LOGE("No destination host found in queued hosts, neither in configuration. Connection closed");
    return R_KILL;
}
示例#2
0
文件: eredis.c 项目: gatezba/eredis
/*
 * EV connect callback
 *
 * EV_TIMER connect_timer
 */
  static void
_eredis_ev_connect_cb (struct ev_loop *loop, ev_timer *w, int revents)
{
  int i;
  eredis_t *e;

  (void) revents;
  (void) loop;

  e = (eredis_t*) w->data;

  if (IS_SHUTDOWN(e)) {
    if (e->hosts_connected) {
      for (i=0; i<e->hosts_nb; i++) {
        host_t *h = &e->hosts[i];
        if (H_IS_CONNECTED(h) && h->async_ctx)
          redisAsyncDisconnect( h->async_ctx );
      }
    }
    else {
      /* Connect timer */
      ev_timer_stop( e->loop, &e->connect_timer );
      /* Async send */
      ev_async_stop( e->loop, &e->send_async );
      /* Event break */
      ev_break( e->loop, EVBREAK_ALL );
    }
    return;
  }

  for (i=0; i<e->hosts_nb; i++) {
    host_t *h = &e->hosts[i];
    switch (H_CONN_STATE( h )) {
      case HOST_F_CONNECTED:
        break;

      case HOST_F_FAILED:
        if ((h->failures < HOST_FAILED_RETRY_AFTER)
            ||
            ( ! _host_connect( h, 0 ))) {
          h->failures %= HOST_FAILED_RETRY_AFTER;
          h->failures ++;
        }
        break;

      case HOST_F_DISCONNECTED:
        if (! _host_connect( h, 0 )) {
          if ((++ h->failures) > HOST_DISCONNECTED_RETRIES) {
            h->failures = 0;
            H_SET_FAILED( h );
          }
        }
        break;

      default:
        break;
    }
  }

  if (! IS_READY(e)) {
    /* Ready flag - need a connected host or a connection failure */
    int nb = 0;
    /* build ready flag */
    for (i=0; i<e->hosts_nb; i++) {
      host_t *h = &e->hosts[i];
      if (H_IS_INIT( h ))
        nb ++;
    }
    if (nb == e->hosts_nb) {
      SET_READY(e);
      e->send_async_pending = 1;
      ev_async_send( e->loop, &e->send_async );
    }
  }
}