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 |
The EventHandler class is used to asynchronously wait for events on a file descriptor. |
Types
Name |
Description |
The Config for SimpleAsyncIO on: ‐ choosing backend implementation ‐ executor to use for receiving completion ‐ max requests are allowed |
Type Aliases
Name |
Description |
Callback invoked with the result of a completed operation. |
Enums
Name |
Description |
Bitset flags describing the I/O events a handler can wait for. |
|
The asynchronized backend to be used: libaio or liburing |
Member Functions
Name |
Description |
|
Construct a SimpleAsyncIO instance with the given configuration. |
|
Destroy the instance, draining any outstanding operations. |
|
Deleted copy assignment; EventHandler objects are not copyable. |
Make an event active. |
|
Attach the handler to a EventBase. |
|
Change the file descriptor that this handler is associated with. |
|
Coroutine version of pread(). |
|
Coroutine version of pwrite(). |
|
Detach the handler from its EventBase. |
|
Return the set of events that we're currently registered for. |
|
|
handlerReady() is invoked when the handler is ready. |
Attach the handler to a EventBase, and change the file descriptor. |
|
Returns true if the handler is currently registered. |
|
Returns true if the handler is registered but has not yet fired. |
|
Initiate an asynchronous read request. |
|
Initiate an asynchronous write request. |
|
Register the handler. |
|
Register the handler as an internal event. |
|
If supported by the backend updates the event to be edge‐triggered. Returns true iff the update was successful. |
|
Unregister the handler, if it is registered. |
Created with MrDocs