Struct asio::IoService [] [src]

pub struct IoService(_);

Methods

impl IoService
[src]

Constructs a new IoService.

Panics

Panics if too many open files.

Examples

use asio::IoService;

let io = IoService::new();

Sets a stop request and cancel all of the waiting event in an IoService.

Examples

use asio::IoService;

let io = IoService::new();
io.stop();

Returns true if this has been stopped.

Examples

use asio::IoService;

let io = IoService::new();
assert_eq!(io.stopped(), false);
io.stop();
assert_eq!(io.stopped(), true);

Resets a stopped IoService.

Examples

use asio::IoService;

let io = IoService::new();
assert_eq!(io.stopped(), false);
io.stop();
assert_eq!(io.stopped(), true);
io.reset();
assert_eq!(io.stopped(), false);

Requests a process to invoke the given handler and return immediately.

Examples

use asio::IoService;
use std::sync::atomic::*;

let io = IoService::new();
static PASS: AtomicBool = ATOMIC_BOOL_INIT;

io.post(|_| PASS.store(true, Ordering::Relaxed));
assert_eq!(PASS.load(Ordering::Relaxed), false);

io.run();
assert_eq!(PASS.load(Ordering::Relaxed), true);

Runs all given handlers.

Examples

use asio::IoService;

let io = IoService::new();
io.run();

Runs all given handlers until call the stop().

This is ensured to not exit until explicity stopped, so it can invoking given handlers in multi-threads.

Examples

Execute 5 parallels event loop (4 thread::spawn + 1 main thread).

use asio::IoService;
use std::thread;

let mut thrds = Vec::new();
IoService::new().work(|io| {
    for _ in 0..4 {
        let io = io.clone();
        thrds.push(thread::spawn(move || io.run()));
    }

    io.post(move |io| {
        io.stop();  // If does not explicity stop, not returns in this `work()`.
    });
});

for thrd in thrds {
    thrd.join().unwrap();
}

Trait Implementations

impl IoObject for IoService
[src]

Returns a IoService associated with this object.

impl Debug for IoService
[src]

Formats the value using the given formatter.

impl Clone for IoService
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more