Code Monkey home page Code Monkey logo

Comments (5)

sfackler avatar sfackler commented on July 17, 2024

A single call to TlsStream::read will do an arbitrarily large number of reads and writes on the underlying socket, but won't return until it's reached EOF (either because the underlying socket is closed, or because the TLS session is closed), or until there's some amount of data ready to copy into the buffer.

from rust-native-tls.

osa1 avatar osa1 commented on July 17, 2024

won't return until it's reached EOF (either because the underlying socket is closed, or because the TLS session is closed), or until there's some amount of data ready to copy into the buffer

How is that even possible to implement? I'm using a non-blocking TcpStream, so TlsStream can't block until there's enough data in the socket to read and fill the buffer. What am I missing?

from rust-native-tls.

sfackler avatar sfackler commented on July 17, 2024

If the underlying stream reports an error (e.g. if there's no data available and the socket's in nonblocking mode), TlsStream returns that error, and the caller will call read again when there's data available.

from rust-native-tls.

osa1 avatar osa1 commented on July 17, 2024

Let me try to explain in different words.

Suppose I have TlsStream<SomeOtherStream>.

SomeOtherStream's read() never blocks.

Suppose that the program only uses TlsStream<SomeOtherStream>.

If there's N bytes in the SomeOtherStream buffer, TlsStream can return M bytes such that M <= N.

So it's possible that SomeOtherStream receives 10 bytes but TlsStream::read returns 5 bytes.

Am I correct so far?

Now suppose that SomeOtherStream received 5 bytes. I call TlsStream::read.

Now it should be possible that this call returns Ok(0) even though the stream is not closed.

So there should be a way to distinguish these two cases:

  1. 0 bytes returned but not because the stream is closed, it's just that the received contents used to maintain TLS connection
  2. 0 bytes returned because the stream is closed

from rust-native-tls.

sfackler avatar sfackler commented on July 17, 2024

Now it should be possible that this call returns Ok(0) even though the stream is not closed.

No, that is not possible.

from rust-native-tls.

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.