Giter Club home page Giter Club logo

Comments (2)

notgull avatar notgull commented on May 27, 2024

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.

bradleyharden avatar bradleyharden commented on May 27, 2024

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.

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 returns Poll::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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.