Skip to content

Commit a2741c5

Browse files
committed
io_uring/net: don't retry recvmsg() unnecessarily
If we're doing multishot receives, then we always end up doing two trips through sock_recvmsg(). For protocols that sanely set msghdr->msg_inq, then we don't need to waste time picking a new buffer and attempting a new receive if there's nothing there. Signed-off-by: Jens Axboe <[email protected]>
1 parent 7d41bcb commit a2741c5

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

io_uring/net.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,15 @@ static inline bool io_recv_finish(struct io_kiocb *req, int *ret,
635635
if (io_aux_cqe(req->ctx, issue_flags & IO_URING_F_COMPLETE_DEFER,
636636
req->cqe.user_data, *ret, cflags | IORING_CQE_F_MORE, true)) {
637637
io_recv_prep_retry(req);
638-
return false;
638+
/* Known not-empty or unknown state, retry */
639+
if (cflags & IORING_CQE_F_SOCK_NONEMPTY ||
640+
msg->msg_inq == -1U)
641+
return false;
642+
if (issue_flags & IO_URING_F_MULTISHOT)
643+
*ret = IOU_ISSUE_SKIP_COMPLETE;
644+
else
645+
*ret = -EAGAIN;
646+
return true;
639647
}
640648
/* Otherwise stop multishot but use the current result. */
641649
}

0 commit comments

Comments
 (0)