Questions tagged [mio]

MIO is a lightweight IO library for Rust with a focus on adding as little overhead as possible over the OS abstractions.

MIO is a lightweight IO library for Rust with a focus on adding as little overhead as possible over the OS abstractions.

41 questions
2
votes
1 answer

What constraints should I be aware of when generating mio's Tokens?

The mio library for asynchronous I/O relies on the developer to provide instances of the Token type in order to correlate events that have happened back to the source, e.g. a particular TcpStream or Handler::Timeout. As you can see from the…
zslayton
  • 51,416
  • 9
  • 35
  • 50
2
votes
1 answer

How to move borrowed content to close connection

The following code should accept tcp connection, read from them, and close them on hangup. extern crate mio; use mio::{EventLoop,Token,ReadHint}; use mio::tcp::{TcpListener, TcpStream}; use std::io::Read; const L_CLIENT: Token = Token(0); const…
michas
  • 25,361
  • 15
  • 76
  • 121
1
vote
2 answers

Is there a recommended rust multi-threaded tcp communication program model?

While learning some Rust, I saw a lot of tutorials that used two very simple models. One is on the server side, where all the accepted tcpstreams are moved to a new thread for use, and the other is on the client side, using blocking reads and then…
progquester
  • 1,228
  • 14
  • 23
1
vote
1 answer

Converting a synchronous Rust IO driver to be `async`

I have a UIO driver that within a so-called wait_on_complete function, polls a file descriptor to wait on an interrupt. This is completely synchronous, so blocks (with a timeout). I'd like to migrate the code such that wait_on_complete is async (or…
Henry Gomersall
  • 8,434
  • 3
  • 31
  • 54
1
vote
1 answer

Why is Mio's poll triggered twice for user-generated events?

The following code generates a "user event" to be returned by poll: extern crate mio; use mio::event::Evented; use mio::{Events, Poll, PollOpt, Ready, Registration, Token}; use std::thread::{sleep, spawn, JoinHandle}; use std::time::{Duration,…
attdona
  • 17,196
  • 7
  • 49
  • 60
1
vote
0 answers

Why would the first write to Mio's TcpStream after accepting give an "operation would block" error?

With this code: poll.poll(&mut poll_events, Some(Duration::from_secs(0))); for event in poll_events.iter() { match event.token() { LISTENER_TOKEN => { let (mut stream, addr) = unwrap_or_continue!( …
Yuri Geinish
  • 16,744
  • 6
  • 38
  • 40
1
vote
0 answers

How to accept a client socket and then poll for the TcpStream in mio?

I cannot figure out how to accept a client socket then start polling for events on the returned TcpStream with mio 0.6. I tried this code, but an event for Token(1) never arrives. Although the accept part is printed out, the client is instantly…
Midiparse
  • 4,701
  • 7
  • 28
  • 48
1
vote
1 answer

Is it possible to register multiple timeouts in mio?

I have written a TCP server in mio and registered multiple timeouts, but only the last registered timeout fires. Do I need a wrapper for my timeouts to combine them or are there any other ways to register multiple timeouts in mio v0.5?
kper
  • 313
  • 3
  • 12
1
vote
1 answer

How to handle errors in mio?

I am building a multithreaded async HTTP server on top of mio. How should I handle events on client TcpStream connections? For is_readable it's pretty straightforward: I read the request and write the response. For other kinds I am not sure.…
ElefEnt
  • 2,027
  • 1
  • 16
  • 20
1
vote
1 answer

How to save reference to handler in hashmap field

I am learning Rust and trying to write a websocket server. The logic is following: WSConnectionFactory creates WSHandler which handle incoming messages and send them to other clients according to arbitrary rules. The problem is that I don't know how…
Sergey
  • 145
  • 1
  • 6
1
vote
1 answer

Native library `kernel32` is being linked to by more than one package

I cloned and tried to build the MIO coroutines library, but its dependencies seem to clash: native library `kernel32` is being linked to by more than one package, and can only be linked to by one package kernel32-sys v0.2.0 kernel32-sys…
LogicChains
  • 4,332
  • 2
  • 18
  • 27
1
vote
1 answer

Trouble with buffer types in mio

I'd like to write an asynchronous server in Rust using mio and I have trouble with the buffer types. I've tried different buffer types and can't get it to work. My current code is: extern crate mio; extern crate bytes; use std::io; use…
elszben
  • 495
  • 1
  • 4
  • 6
1
vote
1 answer

Working with UDP using mio and getting an error "MutBuf is not implemented for the type MutSliceBuf"

For learning purposes I am currently trying to write small program which will implement echo-server for UDP packets which will work on a certain set of ports (say 10000-60000). So as it wouldn't be so good to spam 50k threads for this I need to use…
user3234005
  • 342
  • 1
  • 2
  • 10
1
vote
1 answer

receiving partial UDP packets from mio::udp::UdpSocket.recv

I'm using mio::udp::UdpSocket to receive a response to a request from a client. It looks like I'm getting partial UDP packets on the triggered event. I'm not sure if this is a bug in the mio library or not. I've tried PollOpt::level(), all(),…
bluejekyll
  • 155
  • 2
  • 8
0
votes
1 answer

Generic length of array when reading a stream buffer

I would like to set a generic value (n) in the array based on the bytes that are written in the stream. Now I do not know the exact length of the buffer, I just create a hard coded array to read the stream bytes. use mio::net::TcpStream; ... let…
DustInTheSilence
  • 575
  • 1
  • 7
  • 15