io_uring_prep_cmd(3)

πŸ“¦
version 2.13 Β· 2 versions
  • 2.13 Β· alpine 3.22, alpine 3.23, centos-stream 10, centos-stream 9, debian trixie, fedora 43, fedora 44, opensuse-leap 16.0, ubuntu questing (latest)
  • 2.5 Β· ubuntu noble
, in alpine 3.22, alpine 3.23, centos-stream 10, centos-stream 9, debian trixie, fedora 43, fedora 44, opensuse-leap 16.0, ubuntu questing

io_uring_prep_cmd(3) β€” bestie, it's a liburing manual page πŸ’–

okay so, real talk, this one lives in the liburing manual and its whole vibe is "prep a command request for a socket". Yes, that's the NAME energy: io_uring_prep_cmd_sock β€” prepare a command request for a socket. Slay. Let's get into it. 🫢


✨ SYNOPSIS ✨

#include <liburing.h>

void io_uring_prep_cmd_sock(struct io_uring_sqe *sqe,
                            int cmd_op,
                            int fd,
                            int level,
                            int optname,
                            void *optval,
                            int optlen);

look at those args. seven of them. iconic behaviour honestly. πŸ‘‘


πŸ’… DESCRIPTION πŸ’…

So io_uring_prep_cmd_sock(3) is the function that preps a cmd request for a socket, periodt. It sets up the submission queue entry sqe so that it uses the socket file descriptor that fd is pointing at, and then it kicks off a command operation defined by cmd_op. That's the whole plot. 🌸

And here's the tea: this is a generic function, so every single command out there gets to have its own individual level, optname, and optval values. Meanwhile optlen is what tells everyone how big the thing pointed to by optval actually is. πŸŽ€


πŸ¦‹ Available commands πŸ¦‹

SOCKET_URING_OP_SIOCINQ

Hands you back the amount of queued unread data chillin' in the receive buffer. But bestie β€” the socket must not be in LISTEN state, otherwise you get an error -EINVAL returned in the CQE res field. 😭

Also, for this command, level, optname, optval and optlen are not used. They're just sitting there. Third-wheeling. πŸ™ˆ

A negative return value means an error. That's it, that's the rule.

Wanna know more about this command? Go check unix(7). ✨

Available since 6.7. πŸ”₯

SOCKET_URING_OP_SIOCOUTQ

Returns the amount of unsent data sitting in the socket send queue. And same as before: the socket must not be in LISTEN state, otherwise an error -EINVAL comes back in the CQE res field. πŸ“¬

For this command too, level, optname, optval and optlen are not used.

Negative return value means an error. no cap.

More deets on this command? That's unix(7), babes. πŸ’œ

SOCKET_URING_OP_GETSOCKOPT

This is the command that gets options for the socket referred to by the socket file descriptor fd. The arguments are similar to the getsockopt(2) system call β€” like, cousins, basically. πŸ‘―

Heads up though: SOCKET_URING_OP_GETSOCKOPT is limited to SOL_SOCKET level. Don't try it anywhere else.

And here's the difference from getsockopt(2): instead of doing that thing where the updated optlen value just appears, the updated optlen value is returned in the CQE res field, on success. If it fails? The CQE res contains a negative error number. πŸ’€

SOCKET_URING_OP_SETSOCKOPT

This one sets options for the socket referred to by the socket file descriptor fd. And yep, the arguments are similar to the setsockopt(2) system call. πŸ”§

Available since 6.7. ⭐


🌈 NOTES 🌈

The memory block pointed to by optval needs to stay valid/live until the CQE returns. Do not let it get freed early, bestie, that's how you get chaos. πŸ’€

πŸ’– RETURN VALUE πŸ’–

Dependent on the command. (Yeah, it's giving mysterious. It's per-command, that's just the deal.) 🀷


πŸŽ€ ERRORS πŸŽ€

The CQE res field will contain the result of the operation. That's where you look. That's the vibe check. πŸ‘€


🌟 SEE ALSO 🌟


okay that's the whole page, you ate it, go prep some socket commands πŸ’…βœ¨

this was brought to you by liburing-2.5, dated July 27, 2023 β€” and the liburing Manual, obviously. mwah. 🫢🌸

πŸ“¦ where this page comes from