Skip to content

Commit

Permalink
Add usrsctp_get_timeout()
Browse files Browse the repository at this point in the history
Same as PR sctplab#591 by @oleavr in upstream project which has been ignored for 4 years.

A little change: Instead of using `int` to hold a `uint32_t` (or -1) let's use a `int64_t`.
  • Loading branch information
ibc committed Mar 5, 2024
1 parent 848eca8 commit 28a0c24
Show file tree
Hide file tree
Showing 4 changed files with 33 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);
}

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)
{
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 @@ -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
Expand Down
6 changes: 6 additions & 0 deletions usrsctplib/user_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 2 additions & 0 deletions usrsctplib/usrsctp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 28a0c24

Please sign in to comment.