Questions tagged [rust-tokio]

Tokio is an event-driven, non-blocking I/O platform for writing asynchronous applications with the Rust programming language.

Tokio aims to be:

  • Fast: Tokio's zero-cost abstractions give you bare-metal performance.

  • Productive: Tokio makes it easy to implement protocols and program asynchronously.

  • Reliable: Tokio leverages Rust's ownership and concurrency model to ensure thread safety.

  • Scalable: Tokio has a minimal footprint, and handles backpressure and cancellation naturally.

At a high level, it provides a few major components:

  • A multithreaded, work-stealing based task scheduler.
  • A reactor backed by the operating system's event queue (epoll, kqueue, IOCP, etc...).
  • Asynchronous TCP and UDP sockets.

You can find more information in

1053 questions
0
votes
3 answers

How do I get a static path for tokio::fs::File::open?

The tokio::fs::File::open(path: T + 'static) requires a 'static lifetime on its path parameter. This makes sense because it is handled in runtime threads during the program's execution. I think it would make more sense if you could pass your own…
Markus
  • 512
  • 1
  • 4
  • 21
0
votes
1 answer

Why are spawned futures not executed by tokio_core::reactor::Core?

extern crate tokio; // 0.1.8 use tokio::prelude::*; fn create_a_future(x: u8) -> Box> { Box::new(futures::future::ok(2).and_then(|a| { println!("{}", a); Ok(()) })) } fn main() { let mut…
qweruiop
  • 3,156
  • 6
  • 31
  • 55
0
votes
1 answer

How to chain tokio read functions?

Is there a way to chain the read_* functions in tokio::io in a "recursive" way ? I'm essentially looking to do something like: read_until x then read_exact y then write response then go back to the top. In case you are confused what functions i'm…
George
  • 3,521
  • 4
  • 30
  • 75
0
votes
1 answer

How can I asynchronously retrieve data and modify it with a Tokio-based echo server?

I am working on an echo server which takes data from TCP and applies some logic to that data. For example, if the client data comes in as hello I want to respond it ashello from server. I am able to forward the input data using the copy function,…
Akiner Alkan
  • 6,145
  • 3
  • 32
  • 68
0
votes
1 answer

Is it possible to have Future::and_then conditionally return different futures?

In this simplified version of my code, I would like to sometimes execute the marked line and sometimes not, maybe returning an error instead: extern crate futures; // 0.1.26 extern crate hyper; // 0.12.25 use hyper::rt::{Future, Stream}; use…
0
votes
1 answer

Unable to tokio::run a boxed Future because the trait bound Send is not satisfied

I have a function that should optionally run a future or do nothing, depending on parameters. I tried putting a Box around the two futures that will be returned, a tokio::prelude::future::Done that immediately resolves to Ok(()),…
Lily Mara
  • 3,859
  • 4
  • 29
  • 48
0
votes
2 answers

How to introduce trait indirection with futures?

I have a tokio tcp server which should hand individual incoming connections to a service. How do I correctly handle indirection so that the server can work with different service implementations? I have resorted to calling tokio::spawn() inside the…
Robert Cutajar
  • 3,181
  • 1
  • 30
  • 42
0
votes
1 answer

Why do I get a FrameTooBig error when using Tokio's frame_delimited?

I'm trying to get my feet wet using Tokio. When I send a message from a Telnet connection, I get Custom { kind: InvalidData, error: FrameTooBig }. I don't understand the issue, nor how to overcome it. extern crate tokio; extern crate tokio_io; use…
blasrodri
  • 448
  • 5
  • 16
0
votes
1 answer

Tokio echo server. Cannot read and write in the same future

I'm trying to build an echo server in Tokio. I've seen examples, but all of them seem to use io::copy from Tokio IO which I can't use because I want to modify the output. However, I can't compile a server that uses writer and reader at the same…
0
votes
1 answer

Complete future if certain condition happens

I would like to create a future that completes if a certain value is received over a UDP connection. To clarify, assume I send a ping with id 2 and want to asynchronously wait for the pong with the same id. My idea was to use something like…
Manuel Schmidt
  • 2,429
  • 1
  • 19
  • 32
0
votes
1 answer

How would I make a TcpClient request per item in a futures Stream?

I have a concept project where the client sends a server a number (PrimeClientRequest), the server computes if the value is prime or not, and returns a response (PrimeClientResponse). I want the client to be a simple CLI which prompts the user for a…
Josh Leeb-du Toit
  • 639
  • 1
  • 7
  • 13
0
votes
1 answer

tokio_core::net::UdpCodec with lifetime on associated type

I am trying to implement a tokio_core::net::UdpCodec which create a dns_parser::Packet from the dns_parser crate. The implementation currently look like this: pub struct MdnsCodec; impl UdpCodec for MdnsCodec { type In = dns_parser::Packet; …
Fulkerson
  • 118
  • 2
  • 8
0
votes
1 answer

Using Tokio's mpsc and oneshot leads to deadlock

I want to write a SOCKS server which selects one of several internet gateways depending on the destination as requested by the client. The general flow is Perform SOCKS5 negotiation and derive the address information from client Request an internal…
gin66
  • 1
  • 2
0
votes
1 answer

The trait bound `futures::Future, Error=Box>: Send` is not satisfied

I have the following (simplified) code snippet and I'm trying to run a future on a CpuPool: use futures::{self, Future, IntoFuture}; use std::error; use futures_cpupool::CpuPool; pub struct Store { inner:…
Mohammad Dashti
  • 745
  • 1
  • 9
  • 22
0
votes
0 answers

What is the `||` operator used for when creating a new Tokio TcpServer?

I've been experimenting with the Tokio libraries for playing with TCP servers and clients. A server is almost always constructed like so: TcpServer::new(Http, addr) .serve(|| Ok(HelloWorld)); I'm curious to know what the || operator does and…
nmurthy
  • 1,337
  • 1
  • 12
  • 24