コード例 #1
0
ファイル: sj_timers_mongoose.c プロジェクト: intx82/smart.js
sj_timer_id sj_set_timer(struct timer_info *ti, int msecs, int repeat) {
  struct mg_connection *c;
  struct mg_add_sock_opts opts;
  do {
    ti->id = s_next_timer_id++;
  } while (ti->id == SJ_INVALID_TIMER_ID || sj_find_timer(ti->id) != NULL);
  ti->interval_ms = (repeat ? msecs : -1);
  memset(&opts, 0, sizeof(opts));
  opts.user_data = ti;
  c = mg_add_sock_opt(&sj_mgr, INVALID_SOCKET, sj_timer_handler, opts);
  if (c == NULL) {
    free(ti);
    return 0;
  }
  c->ev_timer_time = mg_time() + (msecs / 1000.0);
  mongoose_schedule_poll();
  return 1;
}
コード例 #2
0
static void mg_rpc_channel_ws_out_reconnect(struct mg_rpc_channel *ch) {
  struct mg_rpc_channel_ws_out_data *chd =
      (struct mg_rpc_channel_ws_out_data *) ch->channel_data;
  if (chd->reconnect_interval > chd->cfg->reconnect_interval_max) {
    chd->reconnect_interval = chd->cfg->reconnect_interval_max;
  }
  if (chd->reconnect_interval == 0) return;
  LOG(LL_DEBUG, ("reconnect in %d", chd->reconnect_interval));

  /* Set reconnect timer */
  {
    struct mg_add_sock_opts opts;
    struct mg_connection *c;
    memset(&opts, 0, sizeof(opts));
    opts.user_data = ch;
    c = mg_add_sock_opt(chd->mgr, INVALID_SOCKET, reconnect_ev_handler, opts);
    if (c != NULL) {
      c->ev_timer_time = mg_time() + chd->reconnect_interval;
      chd->reconnect_interval *= 2;
    }
    chd->fake_timer_connection = c;
  }
}