io\_uring\_prep\_cmd\_sock(3) liburing Manual io\_uring\_prep\_cmd\_sock(3)

# [NAME](#NAME)

io\_uring\_prep\_cmd\_sock - prepare a command request for a socket

# [SYNOPSIS](#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);
```

# [DESCRIPTION](#DESCRIPTION)

The [**io\_uring\_prep\_cmd\_sock**(3)](/man/os/liburing/io_uring_prep_cmd_sock.3) function prepares an cmd request for a socket. The submission queue entry *sqe* is setup to use the socket file descriptor pointed to by *fd* to start an command operation defined by *cmd\_op.*

This is a generic function, and each command has their own individual *level, optname, optval* values. The optlen defines the size pointed by *optval.*

# [Available commands](#Available_commands)

[**SOCKET\_URING\_OP\_SIOCINQ**](#SOCKET_URING_OP_SIOCINQ)

Returns the amount of queued unread data in the receive buffer. The socket must not be in LISTEN state, otherwise an error **-EINVAL** is returned in the CQE *res* field. The following arguments are not used for this command *level, optname, optval* and *optlen.*

Negative return value means an error.

For more information about this command, please check **[unix(7)](/man/os/liburing/unix.7).**

Available since 6.7.

[**SOCKET\_URING\_OP\_SIOCOUTQ**](#SOCKET_URING_OP_SIOCOUTQ)

Returns the amount of unsent data in the socket send queue. The socket must not be in LISTEN state, otherwise an error **-EINVAL** is returned in the CQE *res.* field. The following arguments are not used for this command *level, optname, optval* and *optlen.*

Negative return value means an error.

For more information about this command, please check **[unix(7)](/man/os/liburing/unix.7).**

[**SOCKET\_URING\_OP\_GETSOCKOPT**](#SOCKET_URING_OP_GETSOCKOPT)

Command to get options for the socket referred to by the socket file descriptor *fd.* The arguments are similar to the [**getsockopt(2)**](/man/os/liburing/getsockopt.2) system call.

The **SOCKET\_URING\_OP\_GETSOCKOPT** command is limited to **SOL\_SOCKET** *level.*

Differently from the [**getsockopt(2)**](/man/os/liburing/getsockopt.2) system call, the updated *optlen* value is returned in the CQE *res* field, on success. On failure, the CQE *res* contains a negative error number.

[**SOCKET\_URING\_OP\_SETSOCKOPT**](#SOCKET_URING_OP_SETSOCKOPT)

Command to set options for the socket referred to by the socket file descriptor *fd.* The arguments are similar to the [**setsockopt(2)**](/man/os/liburing/setsockopt.2) system call.

Available since 6.7.

[**SOCKET\_URING\_OP\_TX\_TIMESTAMP**](#SOCKET_URING_OP_TX_TIMESTAMP)

Retrieve transmit timestamps from the socket's error queue. This provides an alternative to the traditional [**recvmsg(2)**](/man/os/liburing/recvmsg.2) error queue interface for obtaining TX timestamps.

The command operates in a polled multishot mode: io\_uring will poll the socket and keep posting timestamps as CQEs until the request is cancelled or fails. The ring must be created with **IORING\_SETUP\_CQE32** or **IORING\_SETUP\_CQE\_MIXED** to provide space for the timestamp data.

The socket must first be configured for timestamping via [**setsockopt(2)**](/man/os/liburing/setsockopt.2) with **SO\_TIMESTAMPING** at the **SOL\_SOCKET** level, specifying the desired timestamp types (e.g. **SOF\_TIMESTAMPING\_TX\_SOFTWARE**, **SOF\_TIMESTAMPING\_TX\_SCHED**, **SOF\_TIMESTAMPING\_TX\_ACK**) along with **SOF\_TIMESTAMPING\_SOFTWARE** and **SOF\_TIMESTAMPING\_OPT\_TSONLY**.

The following arguments are not used for this command: *level, optname, optval* and *optlen.*

Each timestamp is delivered as a CQE with **IORING\_CQE\_F\_MORE** set in *cqe-&gt;flags* to indicate more timestamps may follow. The *cqe-&gt;res* field contains the timestamp key (*tskey*), which corresponds to the byte offset (for TCP) or packet count (for UDP). The timestamp type (*SCM\_TSTAMP\_SCHED*, *SCM\_TSTAMP\_SND* or *SCM\_TSTAMP\_ACK*) is stored in the upper bits of *cqe-&gt;flags* at offset **IORING\_TIMESTAMP\_TYPE\_SHIFT**. If the timestamp is a hardware timestamp, the **IORING\_CQE\_F\_TSTAMP\_HW** flag is set.

The actual timestamp value is stored in the extended CQE area as a **struct io\_timespec** (with 64-bit *tv\_sec* and *tv\_nsec* fields), accessible at *(cqe + 1)*.

The final CQE will not have **IORING\_CQE\_F\_MORE** set, and its *cqe-&gt;res* will contain 0 on success or a negative error code on failure.

Available since 6.17.

[**SOCKET\_URING\_OP\_GETSOCKNAME**](#SOCKET_URING_OP_GETSOCKNAME)

Returns the current address to which the socket is bound. The result is stored in the buffer pointed to by *optval,* which should be a pointer to a *struct sockaddr* (or appropriate variant). The *optlen* argument specifies the size of the buffer. On success, the CQE *res* field contains the actual size of the socket address. If the buffer is too small, the result is truncated.

This is the io\_uring equivalent of [**getsockname**(2)](/man/os/liburing/getsockname.2).

Available since 6.19.

# [NOTES](#NOTES)

The memory block pointed by *optval* needs to be valid/live until the CQE returns.

# [RETURN VALUE](#RETURN_VALUE)

Dependent on the command.

# [ERRORS](#ERRORS)

The CQE *res* field will contain the result of the operation.

# [SEE ALSO](#SEE_ALSO)

[**io\_uring\_get\_sqe**(3)](/man/os/liburing/io_uring_get_sqe.3), [**io\_uring\_submit**(3)](/man/os/liburing/io_uring_submit.3), [**io\_uring\_register**(2)](/man/os/liburing/io_uring_register.2), [**unix**(7)](/man/os/liburing/unix.7)

July 27, 2023 liburing-2.5

---

Document: io_uring_prep_cmd_sock(3) from liburing 2.15-r4 (Chainguard OS)
Source: https://github.com/axboe/liburing.git
