axboe / liburing

Library providing helpers for the Linux kernel io_uring support
MIT License
2.86k stars 402 forks source link

recvmsg returns EINVAL when trying to retrieve control message #917

Closed fabxc closed 3 weeks ago

fabxc commented 1 year ago

I am trying to use io_uring_prep_recvmsg. I set up the struct msghdr correctly but always get an EINVAL return code.

Excerpt from my setup:

      ctx->iov.iov_base = reinterpret_cast<char*>(buf.data()),
      ctx->iov.iov_len = buf.size();

      memset(ctx->cmsg, 0, sizeof(ctx->cmsg));
      ctx->msg.msg_control = ctx->cmsg;
      ctx->msg.msg_controllen = sizeof(ctx->cmsg);
      ctx->msg.msg_iov = &ctx->iov;
      ctx->msg.msg_iovlen = 1;
      io_uring_prep_recvmsg(sqe, fd, &ctx->msg, 0);

If I replace the last line with a plain recvmsg call it works as expected. If I leave msg_control and msg_controllen unset, it also works with io_uring_prep_recvmsg.

My kernel version is 5.4. Are there any known limitations around this?

axboe commented 1 year ago

cmsg is not supported in older kernels, it'll work in newer ones.

alkis commented 1 year ago

Slightly related, is the support in 5.4 missing sockets completely? readv/writev return EINVAL with 5.4 too.

isilence commented 1 year ago

Slightly related, is the support in 5.4 missing sockets completely? readv/writev return EINVAL with 5.4 too.

No, it should work, I think, at least I don't remember any restriction like that

alkis commented 1 year ago

Slightly related, is the support in 5.4 missing sockets completely? readv/writev return EINVAL with 5.4 too.

No, it should work, I think, at least I don't remember any restriction like that

Verified that it does work.