/** * Go through timeout list (for this task only) and remove the first matching * entry, even though the timeout has not triggered yet. * * @note This function only works as expected if there is only one timeout * calling 'handler' in the list of timeouts. * * @param handler callback function that would be called by the timeout * @param arg callback argument that would be passed to handler */ public void sys_untimeout(sys_timeout_handler handler, object arg) { sys_timeo prev_t, t; if (next_timeout == null) { return; } for (t = next_timeout, prev_t = null; t != null; prev_t = t, t = t.next) { if ((t.h == handler) && (t.arg == arg)) { /* We have a match */ /* Unlink from previous in list */ if (prev_t == null) { next_timeout = t.next; } else { prev_t.next = t.next; } /* If not the last one, add time of this one back to next */ if (t.next != null) { t.next.time += t.time; } lwip.memp_free(memp_t.MEMP_SYS_TIMEOUT, t); return; } } return; }
public void sys_timeout(int msecs, sys_timeout_handler handler, object arg) #endif // LWIP_DEBUG_TIMERNAMES { sys_timeo timeout, t; timeout = (sys_timeo)lwip.memp_malloc(memp_t.MEMP_SYS_TIMEOUT); if (timeout == null) { lwip.LWIP_ASSERT("sys_timeout: timeout != null, pool MEMP_SYS_TIMEOUT is empty", timeout != null); return; } timeout.next = null; timeout.h = handler; timeout.arg = arg; timeout.time = msecs; #if LWIP_DEBUG_TIMERNAMES timeout.handler_name = handler_name; lwip.LWIP_DEBUGF(opt.TIMERS_DEBUG, "sys_timeout: {0} msecs={1} handler={2} arg={3}\n", timeout, msecs, handler_name, arg)); #endif // LWIP_DEBUG_TIMERNAMES if (next_timeout == null) { next_timeout = timeout; return; } if (next_timeout.time > msecs) { next_timeout.time -= msecs; timeout.next = next_timeout; next_timeout = timeout; } else { for (t = next_timeout; t != null; t = t.next) { timeout.time -= t.time; if (t.next == null || t.next.time > timeout.time) { if (t.next != null) { t.next.time -= timeout.time; } timeout.next = t.next; t.next = timeout; break; } } } }
/** * Create a one-shot timer (aka timeout). Timeouts are processed in the * following cases: * - while waiting for a message using sys_timeouts_mbox_fetch() * - by calling sys_check_timeouts() (NO_SYS==1 only) * * @param msecs time in milliseconds after that the timer should expire * @param handler callback function to call when msecs have elapsed * @param arg argument to pass to the callback function */ #if LWIP_DEBUG_TIMERNAMES public void sys_timeout_debug(uint msecs, sys_timeout_handler handler, object arg, const pointer handler_name)