Crate mioco [] [src]

Mioco

Scalable, coroutine-based, asynchronous IO handling library for Rust programming language.

Mioco uses asynchronous event loop, to cooperatively switch between coroutines (aka. green threads), depending on data availability. You can think of mioco as of Node.js for Rust or Rust green threads on top of mio.

Mioco API mimics Rust standard library threading API, so it's easy convert existing code to Mioco.

Mioco coroutines should not use any native blocking-IO operations. Any long-running operations, or blocking IO should be executed in mioco::offload() blocks.

Features:

* multithreading support; (see `Config::set_thread_num()`)
* timers (see `timer` module);
* coroutine exit notification (see `JoinHandle`).
* synchronous operations support (see `mioco::offload()`).
* synchronization primitives (see `sync` module):
  * channels (see `sync::mpsc::channel()`);
  * support for synchronization with native environment (outside of Mioco instance)
* user-provided scheduling; (see `Config::set_scheduler()`);

Example:

See examples/echo.rs for an example TCP echo server

Modules

mio

Some mio types that are part of mioco-API, re-exported

sched

Custom scheduling

sync

Useful synchronization primitives

tcp

TCP

timer

Timers

udp

UDP

unix

Unix sockets IO

Macros

select

Select operation on multiple IO.

Structs

Config

Mioco instance builder.

Event

Event delivered to the coroutine

EventSourceId

Id of an event source used to enumerate them.

Handler

Mioco event loop Handler

JoinHandle

Allows to join on mioco Coroutine

MioAdapter

Adapt raw mio type to mioco Evented requirements.

Mioco

Mioco instance.

RW

Read/Write/Both/None

RcEventSource

To share the data between coroutine itself and the coroutine internals referring to the blocked event sources, RcEventSource is being used.

Traits

EventSourceTrait

Trait for coroutine event source

Evented

Mioco event source.

EventedImpl

Utility trait that simplifies implementing Evented

Functions

get_userdata

Get user-provided data of the current coroutine.

in_coroutine

Check if running inside a mioco coroutine.

offload

Execute a block of blocking operations outside of mioco.

select_wait

Block the current coroutine waiting for an event.

set_children_userdata

Set user-provided data for future child coroutines.

set_userdata

Set user-provided data for the current coroutine.

shutdown

Shutdown current mioco instance.

sleep

Block execution for a given time.

sleep_ms

Block execution for a given time.

spawn

Spawn a mioco coroutine that executes the given function.

start

Start a new mioco instance.

start_threads

Start a new mioco instance with a given number of threads.

thread_num

Get number of threads of current mioco instance.

yield_now

Yield execution of the current coroutine.