Skip to content

Commit

Permalink
Add usrsctp_get_timeout()
Browse files Browse the repository at this point in the history
To improve energy efficiency when integrating with an event loop.
  • Loading branch information
oleavr committed May 21, 2021
1 parent e984d7f commit 5fb4b83
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
24 changes: 24 additions & 0 deletions usrsctplib/netinet/sctp_callout.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,30 @@ sctp_os_timer_stop(sctp_os_timer_t *c)
return (1);
}

int
sctp_get_next_tick(void)
{
int 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)
{
Expand Down
1 change: 1 addition & 0 deletions usrsctplib/netinet/sctp_callout.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,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 *);
int sctp_get_next_tick(void);
void sctp_handle_tick(uint32_t);

#define SCTP_OS_TIMER_INIT sctp_os_timer_init
Expand Down
6 changes: 6 additions & 0 deletions usrsctplib/user_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -3352,6 +3352,12 @@ usrsctp_conninput(void *addr, const void *buffer, size_t length, uint8_t ecn_bit
return;
}

int
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));
Expand Down
3 changes: 3 additions & 0 deletions usrsctplib/usrsctp.h
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,9 @@ int
usrsctp_get_events(struct socket *so);


int
usrsctp_get_timeout(void);

void
usrsctp_handle_timers(uint32_t elapsed_milliseconds);

Expand Down

0 comments on commit 5fb4b83

Please sign in to comment.