title | date | author |
---|---|---|
Use Legacy Driver |
2022-06-14 14:00:00 -0700 |
ihciah |
Although Monoio's target platform is Linux that supports io_uring, you can use the Legacy driver when you have no control over this; or when you want to migrate smoothly; or when you want to develop on macOS.
Legacy drivers currently support macOS and Linux, based on kqueue and epoll respectively.
The first way to configure is through macros:
#[monoio::main(driver = "fusion")]
async fn main() { // todo }
In this way, you can pass fusion
, legacy
or uring
as the driver
parameter. Among them, legacy
and uring
will force the use of Legacy and Uring as the IO driver. You can use this method when you know exactly what platform the compiled binary will run on.
Using fusion
as the driver
parameter will dynamically detect the platform's io_uring support at runtime (startup), and prefer io_uring as the IO driver(If you do not specify the driver, fusion mode will be used by default).
The second way is to specify by code:
monoio::RuntimeBuilder::<monoio::FusionDriver>::new()
.enable_timer()
.build()
.expect("Failed building the Runtime")
.block_on(async move {
// todo
})
The generic parameter of RuntimeBuilder
can choose FusionDriver
, IoUringDriver
or LegacyDriver
.
The third is to quickly start through the start
method:
monoio::start::<monoio::LegacyDriver, _>(
async move { // todo }
);
In this way, the generic parameter can be specified as IoUringDriver
or LegacyDriver
.
By default we have turned on the iouring
and legacy
features.
If you turn off the default features and turn it on manually, please note that at least one of these two features must be turned on.
- When only
iouring
is enabled,FusionDriver
(equivalent toIoUringDriver
) andIoUringDriver
are available - When only
legacy
is enabled,FusionDriver
(equivalent toLegacyDriver
) andLegacyDriver
are available - When both features are enabled, using
FusionDriver
can select io driver dynamically.