Example #1
0
static IRAM void mgos_mg_poll_cb(void *arg) {
  mgos_ints_disable();
  s_mg_polls_in_flight--;
  mgos_ints_enable();
  int timeout_ms = 0;
  if (mongoose_poll(0) == 0) {
    /* Nothing is happening now, see when next timer is due. */
    double min_timer = mg_mgr_min_timer(mgos_get_mgr());
    if (min_timer > 0) {
      /* Note: timeout_ms can get negative if a timer is past due. That's ok. */
      timeout_ms = (int) ((min_timer - mg_time()) * 1000.0);
      if (timeout_ms < 0) {
        timeout_ms = 0; /* Now */
      } else if (timeout_ms > MGOS_MONGOOSE_MAX_POLL_SLEEP_MS) {
        timeout_ms = MGOS_MONGOOSE_MAX_POLL_SLEEP_MS;
      }
    } else {
      timeout_ms = MGOS_MONGOOSE_MAX_POLL_SLEEP_MS;
    }
  } else {
    /* Things are happening, we need another poll ASAP. */
  }
  if (timeout_ms == 0) {
    mongoose_schedule_poll(false /* from_isr */);
  } else {
    os_timer_disarm(&s_mg_poll_tmr);
    /* We set repeat = true in case things get stuck for any reason. */
    os_timer_arm(&s_mg_poll_tmr, timeout_ms, 1 /* repeat */);
  }
  (void) arg;
}
Example #2
0
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;
}
Example #3
0
void mg_lwip_mgr_schedule_poll(struct mg_mgr *mgr) {
  (void) mgr;
  mongoose_schedule_poll(false /* from_isr */);
}