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

Bug fix for exasock timeout logic #83

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
17 changes: 13 additions & 4 deletions libs/exasock/socket/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ struct fd_list
struct fd_list* next;
};

static inline struct timespec
convert_timeval_to_timespec(const struct timeval* ts)
{
struct timespec ret;
ret.tv_sec = ts->tv_sec;
ret.tv_nsec = ts->tv_usec * 1000;
return ret;
}

static inline bool
ts_vld(const struct timespec *ts)
{
Expand Down Expand Up @@ -188,7 +197,7 @@ fdlist_insert(struct fd_list** head, int fd)
#define do_socket_poll_timeout(sock, to_val, ready_func, ret, ...) \
do \
{ \
const struct timespec *to = (const struct timespec *)&to_val; \
const struct timespec to = convert_timeval_to_timespec(&to_val);\
struct timespec t_limit, t_now; \
int gen_id = sock->gen_id; \
assert(exa_read_locked(&sock->lock)); \
Expand All @@ -198,7 +207,7 @@ fdlist_insert(struct fd_list** head, int fd)
ret = -1; \
goto __do_socket_poll_timeout_end; \
} \
ts_add(&t_limit, to); \
ts_add(&t_limit, &to); \
while (exa_trylock(&exasock_poll_lock) == 0) \
{ \
if (ready_func(sock, &ret, __VA_ARGS__)) \
Expand Down Expand Up @@ -369,7 +378,7 @@ fdlist_insert(struct fd_list** head, int fd)
#define do_socket_wait_timeout(sock, fd, to_val, ready_func, ret, ...) \
do \
{ \
const struct timespec *to = (const struct timespec *)&to_val; \
const struct timespec to = convert_timeval_to_timespec(&to_val);\
struct timespec t_limit, t_now; \
int gen_id = sock->gen_id; \
assert(exa_read_locked(&sock->lock)); \
Expand All @@ -379,7 +388,7 @@ fdlist_insert(struct fd_list** head, int fd)
ret = -1; \
goto __do_socket_wait_timeout_end; \
} \
ts_add(&t_limit, to); \
ts_add(&t_limit, &to); \
while (exa_trylock(&exasock_poll_lock) == 0) \
{ \
if (ready_func(sock, &ret, __VA_ARGS__)) \
Expand Down