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;Run

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();
}Run

Modules

clock
generic
ip
local
posix
socket_base

Structs

ArcHandler

The binding Arc handler.

Coroutine
CoroutineHandler
DgramSocket

Provides a datagram-oriented socket.

IoService
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
StrandHandler

The binding Strand handler.

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
bind

Provides a Arc handler to asynchronous operation.

raise
read_until
spawn
write_until

Type Definitions

SteadyTimer
SystemTimer