---
name: "io_uring_prep_cmd"
section: "3"
platform: "linux"
package: "liburing-dev"
version: "2.9-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/io_uring_prep_cmd"
---

# io\_uring\_prep\_cmd(3)

prepare a command request for a socket

## NAME

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

## 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

The [**io\_uring\_prep\_cmd\_sock**(3)](/io_uring_prep_cmd_sock/3.md) 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

- **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)](/unix/7.md).**

  Available since 6.7.

- **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)](/unix/7.md).**

- **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)](/getsockopt/2.md)** system call.

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

  Differently from the **[getsockopt(2)](/getsockopt/2.md)** 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**

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

  Available since 6.7.

## NOTES

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

## RETURN VALUE

Dependent on the command.

## ERRORS

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

## SEE ALSO

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