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
16
votes
1 answer

No error for two traits implementing the same method

According to the docs, Rust should complain if I try to call a method provided by two different traits like this: trait Foo { fn f(&self); } trait Bar { fn f(&self); } struct Baz; impl Foo for Baz { fn f(&self) { println!("Baz’s impl…
michas
  • 25,361
  • 15
  • 76
  • 121
6
votes
1 answer

What's the fastest idiomatic way to mutate multiple struct fields at the same time?

Many libraries allow you to define a type which implements a given trait to be used as a callback handler. This requires you to lump all of the data you'll need to handle the event together in a single data type, which complicates borrows. For…
zslayton
  • 51,416
  • 9
  • 35
  • 50
5
votes
1 answer

How do I limit the Tokio threadpool to a certain number of native threads?

What's the correct way of limiting the Tokio (v 0.1.11) threadpool to n OS native threads, where n is an arbitrary number, preferably configurable at runtime? As far as I can tell, it's possible to use Tokio in single threaded mode using using…
George
  • 3,521
  • 4
  • 30
  • 75
5
votes
1 answer

After a load test, every new mio connection immediately hangs up

I wrote a multithreaded asynchronous HTTP server in Rust using mio. When I run a load test (using siege) the server works fine on the first load test but when the load test is done all requests to the server start failing. Using some logging, I…
ElefEnt
  • 2,027
  • 1
  • 16
  • 20
5
votes
0 answers

How to read from a mio TcpStream with a timeout?

I'm using Mioco. mio::net::tcp::TcpStream does not implement Clone, so it seems that it's not possible to share a TcpStream across multiple threads/coroutines (or if it is possible, I'm not sure how; I'm pretty new to Rust). I've hence assumed that…
LogicChains
  • 4,332
  • 2
  • 18
  • 27
4
votes
1 answer

Register a channel with mio

In older versions of the mio doc I find mio::channel, which it seems was used to create a channel implementing EventedFd that can be registered with Poll. I also see on reddit that this was changed in favor of something else, but I can't figure out…
Ulrar
  • 895
  • 8
  • 17
4
votes
0 answers

How can I detect that the client has closed the socket using mio 0.6?

I want a way to detect that the client has closed the socket so I can deregister it, but I can not find any suitable way to do it. My question is similar to Detecting client hangup in MIO, but there are two main differences: I need a cross-platform…
user1244932
  • 7,352
  • 5
  • 46
  • 103
4
votes
1 answer

Detecting client hangup in MIO

When using MIO (0.3.5) how do I detect the termination of a connection? I tried the following: extern crate mio; use mio::{EventLoop,Token,ReadHint}; use std::io::Read; fn main(){ let listener =…
michas
  • 25,361
  • 15
  • 76
  • 121
3
votes
0 answers

"Resource temporarily unavailable" when trying to connect to https websocket with ws-rs (mio)

I am trying to establish a secure connection using Rust ws-rs (based on mio). The part of the code that I think is relevant: impl ws::Handler for Client { fn on_message(&mut self, msg: ws::Message) -> ws::Result<()> { println!("msg =…
Mark
  • 18,730
  • 7
  • 107
  • 130
3
votes
1 answer

What is Mio's behaviour on a Poll with a zero duration timeout?

According to the mio::Poll docs: The function will block until either at least one readiness event has been received or timeout has elapsed. A timeout of None means that poll will block until a readiness event has been received. ... Note that…
Yuri Geinish
  • 16,744
  • 6
  • 38
  • 40
3
votes
0 answers

Why isn't a Box automatically Sized?

I am trying to implement a server using Mio and a reactor pattern. I want my Reactor to handle both TcpListeners and TcpStreams, so abstracting over that is my real challenge here. I have a trait ReAgent that implements various handlers for…
Elf Sternberg
  • 16,129
  • 6
  • 60
  • 68
3
votes
0 answers

How to read Unicode codepoints from an unbuffered file in a mio event loop?

I'd like to use the mio crate to read keypresses as they arrive in an unbuffered fashion. I already have the code to unbuffer stdin, and I have scaffolded the event loop: extern crate mio; extern crate termios; use termios::{Termios, TCSANOW,…
Edd Barrett
  • 3,425
  • 2
  • 29
  • 48
3
votes
0 answers

Can I register one TcpListener on multiple mio Poll objects?

Can I register the same TcpListener on multiple mio Poll objects (one Poll per thread for a multi-threaded server)? When I try, I get the error: thread 'main' panicked at 'called Result::unwrap() on an Err value: Error { repr: Custom(Custom {…
ElefEnt
  • 2,027
  • 1
  • 16
  • 20
3
votes
1 answer

MIO EventLoop is not running for TcpStream

I am a Rust beginner struggling with a problem of async IO. I've decided to use mio. I've read some source code + tutorials but there is still some fundamental part that I do not understand. I am setting up a server with netcat -k -l 127.0.0.1…
Maciej Donajski
  • 298
  • 2
  • 13
2
votes
1 answer

'Connection reset by peer" error for simple TCP server with mio under minor load

I am experimenting with mio to build a high performance tcp server. I started from the example here https://github.com/tokio-rs/mio/blob/master/examples/tcp_server.rs and hit it with hyperfine running this code as a sort of benchmark / feeling the…
JamesGill
  • 183
  • 11
1
2 3