-
Notifications
You must be signed in to change notification settings - Fork 718
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No data coming from Poll #1716
Comments
You are missing something fundamental, I'm sorry to say quite a number of fundamental things. I highly recommend you read the Mio and Hopefully, after reading those you'll realise that Hope this helps. If still have trouble, feel free to ask more questions. |
Hey @Thomasdezeeuw thanks for the links but they're introductions and I'm struggling to understand my solution using them. From what I understand, futures get converted to runnable and set on a task queue to be polled until completed. For this code example, I used |
I don't know what you mean by "futures get converted to runnable".
If you use
If read the
The "does not block" part is important here because otherwise there is little point in using non-blocking I/O that Mio provides.
Are you also making TCP connections? Otherwise you'll get zero events (as nothing has happened).
What is "a request", as TCP doesn't have the concept of a request. Also you code does the following if outcome == () { Which is always true as // Poll the OS for events, waiting at most 100 milliseconds.
poll.poll(&mut events, Some(Duration::from_millis(100)))?;
// Process each event.
for event in events.iter() {
// We can use the token we previously provided to `register` to
// determine for which type the event is.
match event.token() {
SERVER => loop {
// One or more connections are ready, so we'll attempt to
// accept them (in a loop).
match listener.accept() {
Ok((connection, address)) => {
println!("Got a connection from: {}", address);
},
// A "would block error" is returned if the operation
// is not ready, so we'll stop trying to accept
// connections.
Err(ref err) if would_block(err) => break,
Err(err) => return Err(err),
}
}
}
} Btw the code above comes directly from the getting started guide.
Again. Please read the getting started guide, it's very helpful. Yes, it's an "introduction", but you clearly skipped over it before and need to read it (again). |
Yes, this is true, a
Yes, it would. In my initial post, I stated that:
I'm building an async runtime using
Yes, in my initial post, I said the following:
If it's working in the main function instead of being polled in the
Thanks this is the problem. The future polling this TCP listener is now working. It of course exits once it's received a message which is what I was expecting, I'm merely exploring the different ways in which I can poll sockets. In my previous code where it was all running in |
Would be easier if you introduce it as such, I'm not familiar with smol.
But smol is already an async runtime and so is Tokio. And Tokio uses Mio for it's I/O. So what you're trying to achieve doesn't make a lot of sense... You can look at smol and Tokio for inspiration to build an async runtime on top of Mio though. |
@maxwellflitton any update on this? |
If your goal is to integrate |
@Thomasdezeeuw the future now works now I no longer have the |
I'm trying to implement a
Future
trait for a struct to keep polling aTcpListener
however, when I call the port, it prompts the poll to fire but it always prints out the"no events"
printout. If this code just runs in amain
function, it works. However, it's as if no data will ever reach it if it's implemented in aFuture
trait. Am I missing something fundamental?I appreciate that there could be a more optimal implementation, I'm just using this for educational purposes.
The text was updated successfully, but these errors were encountered: