Skip to content

Commit

Permalink
[LibOS] Add post_poll() callback to network sockets
Browse files Browse the repository at this point in the history
Commit "[LibOS] Add secure implementation of eventfd" introduced a
`post_poll()` callback which can be used to trigger additional events on
specific events returned from select/poll/epoll. This commit refactors
the LibOS code such that sockets-specific handling of EINPROGRESS is
moved from select/poll/epoll code into this `post_poll()` callback.

Signed-off-by: Dmitrii Kuvaiskii <dmitrii.kuvaiskii@intel.com>
  • Loading branch information
Dmitrii Kuvaiskii committed Apr 15, 2024
1 parent 51e99f9 commit c59c041
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
10 changes: 10 additions & 0 deletions libos/src/fs/socket/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,15 @@ static int checkin(struct libos_handle* handle) {
return 0;
}

static void post_poll(struct libos_handle* hdl, pal_wait_flags_t* pal_ret_events) {
assert(hdl->type == TYPE_SOCK);

if (*pal_ret_events & (PAL_WAIT_READ | PAL_WAIT_WRITE)) {
bool error_event = !!(*pal_ret_events & (PAL_WAIT_ERROR | PAL_WAIT_HANG_UP));
check_connect_inprogress_on_poll(hdl, error_event);
}
}

static struct libos_fs_ops socket_fs_ops = {
.close = close,
.read = read,
Expand All @@ -235,6 +244,7 @@ static struct libos_fs_ops socket_fs_ops = {
.ioctl = ioctl,
.checkout = checkout,
.checkin = checkin,
.post_poll = &post_poll,
};

struct libos_fs socket_builtin_fs = {
Expand Down
7 changes: 0 additions & 7 deletions libos/src/sys/libos_epoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -679,13 +679,6 @@ static int do_epoll_wait(int epfd, struct epoll_event* events, int maxevents, in
this_item_events |= items[i]->events & (EPOLLOUT | EPOLLWRNORM);
}

/* TODO: move this to socket FS's post_poll() callback */
if (items[i]->handle->type == TYPE_SOCK &&
(pal_ret_events[i] & (PAL_WAIT_READ | PAL_WAIT_WRITE))) {
bool error_event = !!(pal_ret_events[i] & (PAL_WAIT_ERROR | PAL_WAIT_HANG_UP));
check_connect_inprogress_on_poll(items[i]->handle, error_event);
}

if (!this_item_events) {
/* This handle is not interested in events that were detected - epoll item was
* probably updated asynchronously. */
Expand Down
7 changes: 0 additions & 7 deletions libos/src/sys/libos_poll.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,6 @@ static long do_poll(struct pollfd* fds, size_t fds_len, uint64_t* timeout_us) {
if (ret_events[i] & PAL_WAIT_WRITE)
fds[i].revents |= fds[i].events & (POLLOUT | POLLWRNORM);

/* TODO: move this to socket FS's post_poll() callback */
if (libos_handles[i]->type == TYPE_SOCK &&
(ret_events[i] & (PAL_WAIT_READ | PAL_WAIT_WRITE))) {
bool error_event = !!(ret_events[i] & (PAL_WAIT_ERROR | PAL_WAIT_HANG_UP));
check_connect_inprogress_on_poll(libos_handles[i], error_event);
}

if (fds[i].revents)
ret_events_count++;
}
Expand Down

0 comments on commit c59c041

Please sign in to comment.