Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add usrsctp_get_timeout() #1

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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