Skip to content

Commit ac287da

Browse files
committed
io_uring/net: wire up IORING_CQE_F_SOCK_NONEMPTY for accept
If the given protocol supports passing back whether or not we had more pending accept post this one, pass back this information to userspace. This is done by setting IORING_CQE_F_SOCK_NONEMPTY in the CQE flags, just like we do for recv/recvmsg if there's more data available post a receive operation. We can also use this information to be smarter about multishot retry, as we don't need to do a pointless retry if we know for a fact that there aren't any more connections to accept. Suggested-by: Norman Maurer <norman_maurer@apple.com> Acked-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 7951e36 commit ac287da

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

io_uring/net.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,6 +1533,7 @@ int io_accept(struct io_kiocb *req, unsigned int issue_flags)
15331533
.flags = force_nonblock ? O_NONBLOCK : 0,
15341534
};
15351535
struct file *file;
1536+
unsigned cflags;
15361537
int ret, fd;
15371538

15381539
if (!(req->flags & REQ_F_POLLED) &&
@@ -1545,6 +1546,8 @@ int io_accept(struct io_kiocb *req, unsigned int issue_flags)
15451546
if (unlikely(fd < 0))
15461547
return fd;
15471548
}
1549+
arg.err = 0;
1550+
arg.is_empty = -1;
15481551
file = do_accept(req->file, &arg, accept->addr, accept->addr_len,
15491552
accept->flags);
15501553
if (IS_ERR(file)) {
@@ -1573,17 +1576,26 @@ int io_accept(struct io_kiocb *req, unsigned int issue_flags)
15731576
accept->file_slot);
15741577
}
15751578

1579+
cflags = 0;
1580+
if (!arg.is_empty)
1581+
cflags |= IORING_CQE_F_SOCK_NONEMPTY;
1582+
15761583
if (!(req->flags & REQ_F_APOLL_MULTISHOT)) {
1577-
io_req_set_res(req, ret, 0);
1584+
io_req_set_res(req, ret, cflags);
15781585
return IOU_OK;
15791586
}
15801587

15811588
if (ret < 0)
15821589
return ret;
1583-
if (io_req_post_cqe(req, ret, IORING_CQE_F_MORE))
1584-
goto retry;
1590+
if (io_req_post_cqe(req, ret, cflags | IORING_CQE_F_MORE)) {
1591+
if (cflags & IORING_CQE_F_SOCK_NONEMPTY || arg.is_empty == -1)
1592+
goto retry;
1593+
if (issue_flags & IO_URING_F_MULTISHOT)
1594+
return IOU_ISSUE_SKIP_COMPLETE;
1595+
return -EAGAIN;
1596+
}
15851597

1586-
io_req_set_res(req, ret, 0);
1598+
io_req_set_res(req, ret, cflags);
15871599
return IOU_STOP_MULTISHOT;
15881600
}
15891601

0 commit comments

Comments
 (0)