SimpleAsyncIO is a wrapper around AsyncIO intended to hide all the details.

Synopsis

Declared in <folly/io/async/SimpleAsyncIO.h>

class SimpleAsyncIO
    : public EventHandler

Description

Usage: just create an instance of SimpleAsyncIO and then issue IO with pread and pwrite, no other effort required. e.g.:

auto tmpfile = folly::File::temporary(); folly::SimpleAsyncIO aio; aio.pwrite( tmpfile.fd(), "hello world", 11, // size 0, // offset []rc) { LOG(INFO) << "Write completed with rc " << rc; });

IO is dispatched in the context of the calling thread; it may block briefly to obtain a lock on shared resources, but will not block for IO completion. If the IO queue is full (see setMaxRequests(size_t) in Config), IO fails with ‐EBUSY.

IO is completed on the executor specified in the config (global CPU executor by default).

IO is completed by calling the callback function provided to pread/pwrite. The single parameter to the callback is either a negative errno or the number of bytes transferred.

There is a "hidden" EventBase which polls for IO completion and dispatches completion events to the executor. You may specify an existing EventBase in the config (and you are then responsible for making sure the EventBase instance outlives the SimpleAsyncIO instance). If you do not specify one, a ScopedEventBaseThread instance will be created.

Following structure defines the configuration of a SimpleAsyncIO instance, in case you need to override the (sensible) defaults.

Typical usage is something like:

SimpleAsyncIO io(SimpleAsyncIO::Config() .setMaxRequests(100) .setMode(SimpleAsyncIO::Mode::IOURING));

Base Classes

Name

Description

EventHandler

The EventHandler class is used to asynchronously wait for events on a file descriptor.

Types

Name

Description

Config

The Config for SimpleAsyncIO on: ‐ choosing backend implementation ‐ executor to use for receiving completion ‐ max requests are allowed

Type Aliases

Name

Description

SimpleAsyncIOCompletor

Callback invoked with the result of a completed operation.

Enums

Name

Description

EventFlags

Bitset flags describing the I/O events a handler can wait for.

Mode

The asynchronized backend to be used: libaio or liburing

Member Functions

Name

Description

SimpleAsyncIO [constructor]

Construct a SimpleAsyncIO instance with the given configuration.

~SimpleAsyncIO [destructor] [virtual]

Destroy the instance, draining any outstanding operations.

operator= [deleted]

Deleted copy assignment; EventHandler objects are not copyable.

activateEvent

Make an event active.

attachEventBase

Attach the handler to a EventBase.

changeHandlerFD

Change the file descriptor that this handler is associated with.

co_pread

Coroutine version of pread().

co_pwrite

Coroutine version of pwrite().

detachEventBase

Detach the handler from its EventBase.

getRegisteredEvents

Return the set of events that we're currently registered for.

handlerReady [virtual]

handlerReady() is invoked when the handler is ready.

initHandler

Attach the handler to a EventBase, and change the file descriptor.

isHandlerRegistered

Returns true if the handler is currently registered.

isPending

Returns true if the handler is registered but has not yet fired.

pread

Initiate an asynchronous read request.

pwrite

Initiate an asynchronous write request.

registerHandler

Register the handler.

registerInternalHandler

Register the handler as an internal event.

setEdgeTriggered

If supported by the backend updates the event to be edge‐triggered. Returns true iff the update was successful.

unregisterHandler

Unregister the handler, if it is registered.

Created with MrDocs