aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2024-02-24 12:22:52 -0700
committerJens Axboe <axboe@kernel.dk>2024-02-24 12:26:12 -0700
commitb1fa10012528b9ca4d81cc3a24a4a1b46188fc4d (patch)
tree0131c282ed37bc7acdc3864d92b5485a45959d6c
parent2e64761a07bd437ca41071e9eeec9c64342060d8 (diff)
downloadliburing-b1fa10012528b9ca4d81cc3a24a4a1b46188fc4d.tar.gz
examples/proxy: use fixed per-direction msghdr/iov
Decouples it from needing submit, for msg based send/recv. Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--examples/proxy.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/examples/proxy.c b/examples/proxy.c
index 48de55e2..ffc252a4 100644
--- a/examples/proxy.c
+++ b/examples/proxy.c
@@ -89,6 +89,11 @@ struct pending_send {
void *data;
};
+struct io_msg {
+ struct msghdr msg;
+ struct iovec iov;
+};
+
/*
* Per socket stats per connection. For bi-directional, we'll have both
* sends and receives on each socket, this helps track them seperately.
@@ -107,6 +112,8 @@ struct conn_dir {
int mshot_submit;
unsigned long in_bytes, out_bytes;
+
+ struct io_msg io_rcv_msg;
};
enum {
@@ -451,19 +458,20 @@ static void *get_buf(struct conn *c, int bid)
static void __submit_receive(struct io_uring *ring, struct conn *c, int fd)
{
+ struct conn_dir *cd = fd_to_conn_dir(c, fd);
struct conn_buf_ring *cbr = &c->in_br;
struct io_uring_sqe *sqe;
- struct msghdr msg;
- struct iovec iov;
+ struct msghdr *msg = &cd->io_rcv_msg.msg;
+ struct iovec *iov = &cd->io_rcv_msg.iov;
vlog("%d: submit receive fd=%d\n", c->tid, fd);
if (use_msg) {
- memset(&msg, 0, sizeof(msg));
- iov.iov_base = NULL;
- iov.iov_len = 0;
- msg.msg_iov = &iov;
- msg.msg_iovlen = 1;
+ memset(msg, 0, sizeof(*msg));
+ iov->iov_base = NULL;
+ iov->iov_len = 0;
+ msg->msg_iov = iov;
+ msg->msg_iovlen = 1;
}
/*
@@ -485,7 +493,7 @@ static void __submit_receive(struct io_uring *ring, struct conn *c, int fd)
io_uring_prep_recv_multishot(sqe, fd, NULL, 0, 0);
} else {
if (use_msg)
- io_uring_prep_recvmsg(sqe, fd, &msg, 0);
+ io_uring_prep_recvmsg(sqe, fd, msg, 0);
else
io_uring_prep_recv(sqe, fd, NULL, 0, 0);
}