summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author李通洲 <carter.li@eoitek.com>2019-09-16 11:38:22 +0800
committer李通洲 <carter.li@eoitek.com>2019-09-16 11:42:00 +0800
commit6e68fda171686653af586ffd086d14100eefeda5 (patch)
tree2b142a5479ffa148cfb49fe14f3bae7661ba6f52
parentca50c1f776bf20678668dafbb99998741724639b (diff)
downloadliburing-6e68fda171686653af586ffd086d14100eefeda5.tar.gz
liburing-6e68fda171686653af586ffd086d14100eefeda5.tar.bz2
liburing: add io_uring_prep_{recv,send}msg
-rw-r--r--src/include/liburing.h15
-rw-r--r--test/send_recvmsg.c12
2 files changed, 17 insertions, 10 deletions
diff --git a/src/include/liburing.h b/src/include/liburing.h
index 7d884c9..c4189b1 100644
--- a/src/include/liburing.h
+++ b/src/include/liburing.h
@@ -5,6 +5,7 @@
extern "C" {
#endif
+#include <sys/socket.h>
#include <sys/uio.h>
#include <signal.h>
#include <string.h>
@@ -187,6 +188,20 @@ static inline void io_uring_prep_write_fixed(struct io_uring_sqe *sqe, int fd,
sqe->buf_index = buf_index;
}
+static inline void io_uring_prep_recvmsg(struct io_uring_sqe *sqe, int fd,
+ struct msghdr *msg, unsigned flags)
+{
+ io_uring_prep_rw(IORING_OP_RECVMSG, sqe, fd, msg, 1, 0);
+ sqe->msg_flags = flags;
+}
+
+static inline void io_uring_prep_sendmsg(struct io_uring_sqe *sqe, int fd,
+ const struct msghdr *msg, unsigned flags)
+{
+ io_uring_prep_rw(IORING_OP_SENDMSG, sqe, fd, msg, 1, 0);
+ sqe->msg_flags = flags;
+}
+
static inline void io_uring_prep_poll_add(struct io_uring_sqe *sqe, int fd,
short poll_mask)
{
diff --git a/test/send_recvmsg.c b/test/send_recvmsg.c
index ada6559..9b67b61 100644
--- a/test/send_recvmsg.c
+++ b/test/send_recvmsg.c
@@ -61,11 +61,7 @@ static int do_recvmsg(void)
msg.msg_iovlen = 1;
sqe = io_uring_get_sqe(&ring);
- memset(sqe, 0, sizeof(*sqe));
- sqe->opcode = IORING_OP_RECVMSG;
- sqe->fd = sockfd;
- sqe->addr = (uintptr_t) &msg;
- sqe->len = 1;
+ io_uring_prep_recvmsg(sqe, sockfd, &msg, 0);
ret = io_uring_submit(&ring);
if (ret <= 0) {
@@ -133,11 +129,7 @@ static int do_sendmsg(void)
}
sqe = io_uring_get_sqe(&ring);
- memset(sqe, 0, sizeof(*sqe));
- sqe->opcode = IORING_OP_SENDMSG;
- sqe->fd = sockfd;
- sqe->addr = (uintptr_t) &msg;
- sqe->len = 1;
+ io_uring_prep_sendmsg(sqe, sockfd, &msg, 0);
ret = io_uring_submit(&ring);
if (ret <= 0) {