Crate asyncio [] [src]

The asyncio is Asynchronous Input/Output library.

Usage

This crate is on github and can be used by adding asyncio to the dependencies in your project's Cargo.toml.

[dependencies]
rust_asio = "*"

And this in your crate root:

extern crate asyncio;Run

For example, TCP connection code:

use std::io;
use std::sync::Arc;
use asyncio::*;
use asyncio::ip::*;
use asyncio::socket_base::*;

fn on_accept(sv: Arc<TcpListener>, res: io::Result<(TcpSocket, TcpEndpoint)>) {
  match res {
    Ok((soc, ep)) => { /* do something */ },
    Err(err) => panic!("{}", err),
  }
}

fn on_connect(cl: Arc<TcpSocket>, res: io::Result<()>) {
  match res {
    Ok(_) => { /* do something */ },
    Err(err) => panic!("{}", err),
  }
}

fn main() {
  let io = &IoService::new();

  let sv = Arc::new(TcpListener::new(io, Tcp::v4()).unwrap());
  sv.set_option(ReuseAddr::new(true)).unwrap();
  let ep = TcpEndpoint::new(IpAddrV4::any(), 12345);
  sv.bind(&ep).unwrap();
  sv.listen().unwrap();
  sv.async_accept(wrap(on_accept, &sv));

  let cl = Arc::new(TcpSocket::new(io, Tcp::v4()).unwrap());
  cl.async_connect(&ep, wrap(on_connect, &cl));

  io.run();
}Run

Modules

clock
generic
ip
local
posix
socket_base

Structs

Coroutine
DgramSocket

Provides a datagram-oriented socket.

IoService
IoServiceWork
RawSocket

Provides a raw-oriented socket.

SeqPacketSocket

Provides a sequenced packet socket.

SignalSet

Provides a signal.

SocketListener

Provides a ability to accept new connections.

Strand
StreamBuf
StreamSocket

Provides a stream-oriented socket.

Enums

Shutdown

Possible values which can be passed to the shutdown method.

Signal

Traits

Endpoint
GetSocketOption
Handler
IoControl
IoObject

Traits to the associated with IoService.

MatchCondition
Protocol
SetSocketOption
SockAddr
SocketOption
Stream

Functions

async_read_until
async_write_until
raise
read_until
wrap

Provides a Arc handler to asynchronous operation.

write_until

Type Definitions

SteadyTimer
SystemTimer