Giter VIP home page Giter VIP logo

Comments (7)

ezh avatar ezh commented on August 18, 2024

I can apply a workaround, but certainly, preemptively checking the connection status before each read would not be the most efficient or elegant solution.

from gnet.

ezh avatar ezh commented on August 18, 2024

Honestly, I'm quite surprised that huge corporations are using the code with such behavior in production. Thank you for the code, anyway.

from gnet.

panjf2000 avatar panjf2000 commented on August 18, 2024

I fail to see what is bothering you. What's your problem with io.ErrShortBuffer?

from gnet.

ezh avatar ezh commented on August 18, 2024

io.ErrShortBuffer indicates at the same time:

  1. there is a short buffer
  2. there is not enough data
  3. there is a closed connection
    For example, if there is not enough data, the read operation should be repeated after a while to get a new portion. However, there is no reason to do that in case of a closed connection.
    Am I wrong?
    I may have missed an example of how to do it correctly.

We expect to get 3 bytes.

  1. conn.Read returns io.ErrShortBuffer because there is no data at all
  2. do conn.Read one more time, the client sends 1 byte, and we have io.ErrShortBuffer again
  3. the connection took too long, we close the connection in a separate goroutine
  4. conn.Read returns io.ErrShortBuffer again

Do you think the behavior is correct? If so, I'll close the report. 🤷‍♂️

from gnet.

ezh avatar ezh commented on August 18, 2024

I understand that we can track the status with the event handler, or even write the custom state machine.

But my question is about conn.Read behavior.

from gnet.

panjf2000 avatar panjf2000 commented on August 18, 2024

gnet is a event-driven framework, you should only read data in OnTraffic, why would you call Read() constantly to check if there is data coming? I don't think you're using gnet in the right way.

from gnet.

ezh avatar ezh commented on August 18, 2024

Thank you for your quick feedback. I appreciate your guidance and will verify the usage to align with best practices.

Maybe I didn't get the idea.

from gnet.

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.