Comments (2)
I think that your two futures in spawn_connections
could be implemented using smol::io::copy
, which properly handles checking for zero-sized reads indicating EOF.
One of the main architectural differences between Tokio and Smol is that Tokio's reactor uses edge-triggered polling while Smol's uses oneshot polling. The intuitive way to think about this is:
- Tokio checks for incoming data on the socket and then reads from it.
- Smol tries to read/write/whatever from the socket, and if there is no data, waits for new data.
In most cases the user facing differences between these two approaches is not noticeable. However, since there is no more incoming data Tokio returns Poll::Pending
when trying to read from a closed socket. On the other hand Smol returns Poll::Ready(0)
.
from smol.
I think that your two futures in
spawn_connections
could be implemented usingsmol::io::copy
, which properly handles checking for zero-sized reads indicating EOF.
This was just a minimal example. In my actual code, I perform some modifications to the stream, so copy
wouldn't be a viable option.
One of the main architectural differences between Tokio and Smol is that Tokio's reactor uses edge-triggered polling while Smol's uses oneshot polling.
Yes, I was at least tangentially aware of this. I encountered the problem above in integration tests using tokio
/smol
, but my actual code uses mio
directly. And since mio
doesn't have configurable polling, I had to adapt my code for edge-triggering. I only later discovered polling
. I wish I would have seen it earlier, since level-triggering would have been more appropriate for my situation.
However, since there is no more incoming data Tokio returns
Poll::Pending
when trying to read from a closed socket. On the other hand Smol returnsPoll::Ready(0)
.
I thought this might be a conscious design decision, but I wasn't sure. Thanks for clarifying. I'll be sure to keep that difference in mind in the future.
Thanks for answering my question.
from smol.
Related Issues (20)
- async-net add TcpSocket? HOT 1
- It's not clear how to use Executor instead of smol::spawn HOT 1
- smol violates API guidelines' "C-STABLE" HOT 2
- TLS example should use `async_tls` instead of `async-native-tls`
- RUSTSEC-2021-0060: `aes-soft` has been merged into the `aes` crate HOT 1
- RUSTSEC-2021-0059: `aesni` has been merged into the `aes` crate HOT 1
- RUSTSEC-2021-0064: `cpuid-bool` has been renamed to `cpufeatures` HOT 1
- RUSTSEC-2020-0056: stdweb is unmaintained HOT 1
- RUSTSEC-2018-0017: `tempdir` crate has been deprecated; use `tempfile` instead HOT 1
- smol::spawn: BrokenPipe io::copy failed
- Panic: "There is no reactor running, must be called from the context of a Tokio 1.x runtime" HOT 3
- Give smol-rs a logo/mascot HOT 3
- Tracking issue for potentially useful features in future Rust versions HOT 11
- Tracking issue for smol v2.0.0 HOT 9
- Should we expose event-listener in this crate? HOT 3
- concurrent futures combinators with smol HOT 1
- Figure out a way to race multiple futures in smol HOT 5
- Destructors aren't run for detached tasks HOT 5
- File write just before exit seems racey HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from smol.