---
name: "io_uring_prep_accept"
section: "3"
platform: "linux"
package: "liburing"
version: "2.15-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/io_uring_prep_accept"
---

# io\_uring\_prep\_accept(3)

prepare an accept request

## NAME

io\_uring\_prep\_accept - prepare an accept request

## SYNOPSIS

```
#include <sys/socket.h>
#include <liburing.h>
```

**void io\_uring\_prep\_accept(struct io\_uring\_sqe \****sqe***,**                           **int** *sockfd***,**                           **struct sockaddr \****addr***,**                           **socklen\_t \****addrlen***,**                           **int** *flags***);**

**void io\_uring\_prep\_accept\_direct(struct io\_uring\_sqe \****sqe***,**                                  **int** *sockfd***,**                                  **struct sockaddr \****addr***,**                                  **socklen\_t \****addrlen***,**                                  **int** *flags***,**                                  **unsigned int** *file\_index***);**

**void io\_uring\_prep\_multishot\_accept(struct io\_uring\_sqe \****sqe***,**                                     **int** *sockfd***,**                                     **struct sockaddr \****addr***,**                                     **socklen\_t \****addrlen***,**                                     **int** *flags***);**

**void io\_uring\_prep\_multishot\_accept\_direct(struct io\_uring\_sqe \****sqe***,**                                            **int** *sockfd***,**                                            **struct sockaddr \****addr***,**                                            **socklen\_t \****addrlen***,**                                            **int** *flags***);**

## DESCRIPTION

The [**io\_uring\_prep\_accept**(3)](/io_uring_prep_accept/3.md) function and its three variants prepare an accept request similar to [**accept4**(2)](/accept4/2.md). The submission queue entry *sqe* is setup to use the file descriptor *sockfd* to start accepting a connection request described by the socket address at *addr* and of structure length *addrlen* and using modifier flags in *flags*.

The three variants allow combining the direct file table and multishot features.

Direct descriptors are io\_uring private file descriptors. They avoid some of the overhead associated with thread shared file tables and can be used in any io\_uring request that takes a file descriptor. The two direct variants here create such direct descriptors. Subsequent to their creation, they can be used by setting **IOSQE\_FIXED\_FILE** in the SQE *flags* member, and setting the SQE *fd* field to the direct descriptor value rather than the regular file descriptor. Direct descriptors are managed like registered files.

To use an accept direct variant, the application must first have registered a file table of a desired size using [**io\_uring\_register\_files**(3)](/io_uring_register_files/3.md) or [**io\_uring\_register\_files\_sparse**(3)](/io_uring_register_files_sparse/3.md). Once registered, [**io\_uring\_prep\_accept\_direct**(3)](/io_uring_prep_accept_direct/3.md) allows an entry in that table to be specifically selected through the *file\_index* argument. If the specified entry already contains a file, the file will first be removed from the table and closed, consistent with the behavior of updating an existing file with [**io\_uring\_register\_files\_update**(3)](/io_uring_register_files_update/3.md). *file\_index* can also be set to **IORING\_FILE\_INDEX\_ALLOC** for this variant and an unused table index will be dynamically chosen and returned. Likewise, **io\_uring\_prep\_multishot\_accept\_direct** will have an unused table index dynamically chosen and returned for each connection accepted. If both forms of direct selection will be employed, specific and dynamic, see [**io\_uring\_register\_file\_alloc\_range**(3)](/io_uring_register_file_alloc_range/3.md) for setting up the table so dynamically chosen entries are made against a different range than that targeted by specific requests.

Note that old kernels don't check the SQE *file\_index* field meaning applications cannot rely on a **-EINVAL** CQE *res* being returned when the kernel is too old because older kernels may not recognize they are being asked to use a direct table slot.

When a direct descriptor accept request asks for a table slot to be dynamically chosen but there are no free entries, **-ENFILE** is returned as the CQE *res*.

The multishot variants allow an application to issue a single accept request, which will repeatedly trigger a CQE when a connection request comes in. Like other multishot type requests, the application should look at the CQE *flags* and see if **IORING\_CQE\_F\_MORE** is set on completion as an indication of whether or not the accept request will generate further CQEs. Note that for the multishot variants, setting **addr** and **addrlen** may not make a lot of sense, as the same value would be used for every accepted connection. This means that the data written to **addr** may be overwritten by a new connection before the application has had time to process a past connection. If the application knows that a new connection cannot come in before a previous one has been processed, it may be used as expected. The multishot variants are available since 5.19.

See the man page [**accept4**(2)](/accept4/2.md) for details of the accept function itself.

## RETURN VALUE

None

## ERRORS

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

[**io\_uring\_prep\_accept**(3)](/io_uring_prep_accept/3.md) generates the installed file descriptor as its result.

[**io\_uring\_prep\_accept\_direct**(3)](/io_uring_prep_accept_direct/3.md) and *file\_index* set to a specific direct descriptor generates **0** on success. The caller must remember which direct descriptor was picked for this request.

[**io\_uring\_prep\_accept\_direct**(3)](/io_uring_prep_accept_direct/3.md) and *file\_index* set to **IORING\_FILE\_INDEX\_ALLOC** generates the dynamically chosen direct descriptor.

[**io\_uring\_prep\_multishot\_accept**(3)](/io_uring_prep_multishot_accept/3.md) generates the installed file descriptor in each result.

[**io\_uring\_prep\_multishot\_accept\_direct**(3)](/io_uring_prep_multishot_accept_direct/3.md), generates the dynamically chosen direct descriptor in each result.

Note that where synchronous system calls will return **-1** on failure and set *errno* to the actual error value, io\_uring never uses *errno*. Instead it generates the negated *errno* directly in the CQE *res* field.

## NOTES

As with any request that passes in data in a struct, that data must remain valid until the request has been successfully submitted. It need not remain valid until completion. Once a request has been submitted, the in-kernel state is stable. Very early kernels (5.4 and earlier) required state to be stable until the completion occurred. Applications can test for this behavior by inspecting the **IORING\_FEAT\_SUBMIT\_STABLE** flag passed back from [**io\_uring\_queue\_init\_params**(3)](/io_uring_queue_init_params/3.md).

Note that the direct versions of accept do not accept **SOCK\_CLOEXEC ,** and setting that flag will result in an **-EINVAL** error in the CQE.

## 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\_files**(3)](/io_uring_register_files/3.md), [**io\_uring\_register\_files\_sparse**(3)](/io_uring_register_files_sparse/3.md), [**io\_uring\_register\_file\_alloc\_range**(3)](/io_uring_register_file_alloc_range/3.md), [**io\_uring\_register**(2)](/io_uring_register/2.md), [**accept4**(2)](/accept4/2.md)
