Crate asio [] [src]

The asio is Asynchronous Input/Output library.

Usage

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

[dependencies]
rust_asio = "*"

And this in your crate root:

extern crate asio;

For example, TCP connection code:

use std::io;
use std::sync::Arc;
use asio::*;
use asio::ip::*;
use asio::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(bind(on_accept, &sv));

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

  io.run();
}

Modules

clock
ip
local
posix
socket_base

Structs

ArcHandler

The binding Arc handler.

Coroutine
DgramSocket
IoService
RawSocket
SeqPacketSocket
SocketListener
Strand
StrandHandler

The binding Strand handler.

StreamBuf
StreamSocket

Enums

Shutdown

Possible values which can be passed to the shutdown method.

Traits

Endpoint
FromRawFd
GetSocketOption
Handler
IoControl
IoObject

Traits to the associated with IoService.

MatchCondition
Protocol
SetSocketOption
SocketOption
Stream

Functions

async_read_until
async_write_until
bind

Provides a primitive handler to asynchronous operation.

read_until
spawn
write_until

Type Definitions

SteadyTimer
SystemTimer