コード例 #1
0
ファイル: tt_dns_native.c プロジェクト: newser/TitanSDK
tt_result_t tt_dns_create_ntv(IN ares_channel ch)
{
    if (ch->nservers != 0) {
        __dskt_t *dskt;
        int i;

        dskt = tt_malloc(sizeof(__dskt_t) * __DSKT_NUM(ch));
        if (dskt == NULL) {
            TT_ERROR("no mem for dns wov");
            return TT_FAIL;
        }

        for (i = 0; i < __DSKT_NUM(ch); ++i) {
            __dskt_init(&dskt[i], ch);
        }

        // save dskt in ch->sock_create_cb_data. note ares_dup()
        // would copy the pointer, then two ares_channels would
        // share same dskts, which is not expected, so must do a
        // "deep copy" if ares_dup() is called
        ares_set_socket_callback(ch, NULL, dskt);
    }

    ares_set_socket_functions(ch, &__dskt_itf, ch);

    return TT_SUCCESS;
}
コード例 #2
0
ファイル: query.c プロジェクト: 4Second2None/libphenom
static ph_dns_channel_t *create_chan(void)
{
  ph_dns_channel_t *chan;
  struct ares_options opts;
  int res;
  pthread_mutexattr_t attr;

  chan = ph_mem_alloc(mt.chan);
  if (!chan) {
    return NULL;
  }

  pthread_mutexattr_init(&attr);
  pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
  pthread_mutex_init(&chan->chanlock, &attr);
  pthread_mutexattr_destroy(&attr);

  if (ph_ht_init(&chan->sock_map, 4, &sock_key, &ph_ht_ptr_val_def) != PH_OK) {
    ph_panic("failed to init sock map");
  }

  memset(&opts, 0, sizeof(opts));
  opts.sock_state_cb_data = chan;
  opts.sock_state_cb = sock_state_cb;
  opts.flags = ARES_FLAG_STAYOPEN;

  res = ares_init_options(&chan->chan, &opts,
      ARES_OPT_SOCK_STATE_CB|ARES_OPT_FLAGS);

  if (res != ARES_SUCCESS) {
    ph_panic("failed to ares_init_options: %s", ares_strerror(res));
  }

  ares_set_socket_callback(chan->chan, sock_create_cb, chan);

  return chan;
}