Comments (7)
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.
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.
I fail to see what is bothering you. What's your problem with io.ErrShortBuffer
?
from gnet.
io.ErrShortBuffer
indicates at the same time:
- there is a short buffer
- there is not enough data
- 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.
conn.Read
returnsio.ErrShortBuffer
because there is no data at all- do
conn.Read
one more time, the client sends 1 byte, and we haveio.ErrShortBuffer
again - the connection took too long, we close the connection in a separate goroutine
- conn.Read returns
io.ErrShortBuffer
again
Do you think the behavior is correct? If so, I'll close the report. 🤷♂️
from gnet.
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.
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.
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)
- Special treatment for the first package HOT 8
- [Question]: How to shut down the started tcp server and turn off port listening? HOT 2
- [Question]: When using io.CopyBuffer(), do you need to call Flush to send the data? HOT 2
- [Bug]: Discard() panic HOT 17
- [Feature]: `io_uring` support HOT 6
- [Question]: there's gnet https server now, how to use gnet https client? HOT 1
- UDP FD handle is not released HOT 1
- [Question]: The redis server service implemented using gnet has too many read tcp i/o timeouts in the production environment. HOT 6
- [Question]: redhub upgraded to use gnet/v2 issues, seemed "stalled" HOT 1
- [Feature]: tls support HOT 5
- [Bug]: gnet.Conn.Peek crashes slice bounds out of range HOT 6
- [bug]: socket fd being reused during `OnClose()` lead to data corruption HOT 6
- [Question]: where is the example project? HOT 3
- [Question]: type engine struct { HOT 2
- [Question]: Does udp buffer support on-demand allocation? HOT 2
- [Question]: client blocks when dialing new connections HOT 19
- [Question]: How to set the client write timeout parameter? HOT 2
- [Question]: Communicate with netty HOT 2
- [Bug]: concurrent map write and read HOT 7
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 gnet.