diff --git a/usrsctplib/netinet/sctp_callout.c b/usrsctplib/netinet/sctp_callout.c index ee6cd4cdd..73601433c 100755 --- a/usrsctplib/netinet/sctp_callout.c +++ b/usrsctplib/netinet/sctp_callout.c @@ -150,6 +150,30 @@ sctp_os_timer_stop(sctp_os_timer_t *c) return (1); } +int64_t +sctp_get_next_tick(void) +{ + int64_t ret; + sctp_os_timer_t *c; + + SCTP_TIMERQ_LOCK(); + c = TAILQ_FIRST(&SCTP_BASE_INFO(callqueue)); + if (c) { + uint32_t min_delta = UINT32_MAX; + while (c) { + uint32_t delta = c->c_time - ticks; + min_delta = (delta < min_delta) ? delta : min_delta; + c = TAILQ_NEXT(c, tqe); + } + ret = min_delta; + } else { + ret = -1; + } + SCTP_TIMERQ_UNLOCK(); + + return ret; +} + void sctp_handle_tick(uint32_t elapsed_ticks) { diff --git a/usrsctplib/netinet/sctp_callout.h b/usrsctplib/netinet/sctp_callout.h index 2a78e414f..437868f30 100755 --- a/usrsctplib/netinet/sctp_callout.h +++ b/usrsctplib/netinet/sctp_callout.h @@ -87,6 +87,7 @@ void sctp_os_timer_init(sctp_os_timer_t *tmr); int sctp_os_timer_start(sctp_os_timer_t *, uint32_t, void (*)(void *), void *); /* Returns 1 if pending timer was stopped, 0 otherwise. */ int sctp_os_timer_stop(sctp_os_timer_t *); +int64_t sctp_get_next_tick(void); void sctp_handle_tick(uint32_t); #define SCTP_OS_TIMER_INIT sctp_os_timer_init diff --git a/usrsctplib/user_socket.c b/usrsctplib/user_socket.c index cde6ecc41..bdab5f4b7 100755 --- a/usrsctplib/user_socket.c +++ b/usrsctplib/user_socket.c @@ -3331,6 +3331,12 @@ usrsctp_conninput(void *addr, const void *buffer, size_t length, uint8_t ecn_bit return; } +int64_t +usrsctp_get_timeout(void) +{ + return sctp_get_next_tick(); +} + void usrsctp_handle_timers(uint32_t elapsed_milliseconds) { sctp_handle_tick(sctp_msecs_to_ticks(elapsed_milliseconds)); diff --git a/usrsctplib/usrsctp.h b/usrsctplib/usrsctp.h index 93e89b386..df487cc4b 100644 --- a/usrsctplib/usrsctp.h +++ b/usrsctplib/usrsctp.h @@ -1049,6 +1049,8 @@ usrsctp_set_upcall(struct socket *so, int usrsctp_get_events(struct socket *so); +int64_t +usrsctp_get_timeout(void); void usrsctp_handle_timers(uint32_t elapsed_milliseconds);