Skip to contentSkip to conversation

example/io_uring-test.c: change to use real readv

PATCH New Bob Liu 1 participant 1 message Feb 17, 2020 io_uring

lore
Share & tools
lore

Bob Liu

author
#0 lore raw

PATCH 1/1 example/io_uring-test.c: change to use real readv

Readv can read vecs in one sqe instead of multi sqe.

---
 examples/io_uring-test.c | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)
examples/io_uring-test.c +7 -14
index 4f5ebf6..96fa4d1 100644
@@ -20,7 +20,6 @@ int main(int argc, char *argv[])
 	struct io_uring_sqe *sqe;
 	struct io_uring_cqe *cqe;
 	struct iovec *iovecs;
-	off_t offset;
 	void *buf;
 
 	if (argc < 2) {
@@ -28,7 +27,7 @@ int main(int argc, char *argv[])
 		return 1;
 	}
 
-	ret = io_uring_queue_init(QD, &ring, 0);
+	ret = io_uring_queue_init(1, &ring, 0);
 	if (ret < 0) {
 		fprintf(stderr, "queue_init: %s\n", strerror(-ret));
 		return 1;
@@ -48,16 +47,10 @@ int main(int argc, char *argv[])
 		iovecs[i].iov_len = 4096;
 	}
 
-	offset = 0;
-	i = 0;
-	do {
-		sqe = io_uring_get_sqe(&ring);
-		if (!sqe)
-			break;
-		io_uring_prep_readv(sqe, fd, &iovecs[i], 1, offset);
-		offset += iovecs[i].iov_len;
-		i++;
-	} while (1);
+	sqe = io_uring_get_sqe(&ring);
+	if (!sqe)
+		return 1;
+	io_uring_prep_readv(sqe, fd, iovecs, QD, 0);
 
 	ret = io_uring_submit(&ring);
 	if (ret < 0) {
@@ -76,8 +69,8 @@ int main(int argc, char *argv[])
 
 		done++;
 		ret = 0;
-		if (cqe->res != 4096) {
-			fprintf(stderr, "ret=%d, wanted 4096\n", cqe->res);
+		if (cqe->res != 4096 * QD) {
+			fprintf(stderr, "ret=%d, wanted=%d\n", cqe->res, 4096*QD);
 			ret = 1;
 		}
 		io_uring_cqe_seen(&ring, cqe);
Signature · 1 line
2.17.1