Git Product home page Git Product logo

Comments (7)

ctz avatar ctz commented on May 27, 2024 1

Yeah we should fix the example code to deal with short writes for good form.

Though, in practice, there is really zero chance I think that that would ever happen with a real TCP sockets -- the server has written no data, so the write window is at least the MTU (the smallest of which is 68 bytes, and easily fits one alert). Though perhaps it's possible for protocols that upgrade to TLS from another protocol, like SMTP STARTTLS.

from rustls.

jbr avatar jbr commented on May 27, 2024 1

Maybe an AcceptedAlert::write_all(&mut io) -> io::Result<()> would improve ergonomics for blocking usage?

from rustls.

jbr avatar jbr commented on May 27, 2024 1

I don't think blocking would be the concern since the underlying io is set to non-blocking and so would return ErrorKind::WouldBlock and presumably early-return from the loop. This probably would be fine, since the async wrapper could do something roughly like the following:

return match alert.write(io) {
  Err(e) if e.kind() == ErrorKind::WouldBlock => Poll::Pending,
  other => Poll::Ready(other)
}

The loop in write would likely never continue in async usage because even a successful write is WouldBlock.

from rustls.

cpu avatar cpu commented on May 27, 2024 1

Maybe an AcceptedAlert::write_all(&mut io) -> io::Result<()> would improve ergonomics for blocking usage?

That's a good suggestion, thanks. I added a commit for this in #1868 and switched the acceptor example update commit to use it.

from rustls.

djc avatar djc commented on May 27, 2024

Fair point, we've been noticing this stuff in tokio-rustls: rustls/tokio-rustls#48.

from rustls.

cpu avatar cpu commented on May 27, 2024

Yeah we should fix the example code to deal with short writes for good form.

Here's a quick patch for the doc update & example's usage of AcceptedAlert::write: #1868

It might make sense to do a more systematic evaluation of all the examples + writes as a follow up to make sure we address this holistically.

from rustls.

jsha avatar jsha commented on May 27, 2024

Good point @jbr - or we could change the behavior of write() to do write_all(), since as @ctz says this would never happen with a real TCP socket. So we would pay the price of possibly blocking an async executor in a very unlikely situation for the convenience of users not having to loop over the result.

from rustls.

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.