Comments (10)
This result is completely different from the result returned in the case comment.
from ergo.
If I do understand your question correctly... The main reason for returning left
, await
values is that you might receive a packet with the tail of your logical struct and the header of the next one. In this case, gen.TCP will append the tail data to the packet buffer and invoke HandlePacket with the packet containing the full logical struct while keeping the head data for the next packet.
from ergo.
i get it
thank you
from ergo.
I send a slice -> [3 217 0 0 26 0 0 0 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90]
I send divided into two this slice
3 seconds at intervals
e.g.
dial.Write(slice[:4])
time.Sleep(time.Second * 3)
dial.Write(slice[4:])
but when when call HandlePacket first call
This branch will be triggered:
plen := len(packet) if plen < headLength { log.Errorf("packet too short %d", plen) return plen, headLength, gen.TCPHandlerStatusOK }
when I send slice[4:]. second call HandlePacket
packet data is -> [26 0 0 0 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90]
where is my first data?
from ergo.
not sure if I follow your example. could you please share your HandlePacket code and what you expected to see
from ergo.
func (this *handle) HandlePacket(process *gen.TCPHandlerProcess, packet []byte, conn *gen.TCPConnection) (int, int, gen.TCPHandlerStatus) {
plen := len(packet)
if plen < headLength {
log.Errorf("packet too short %d", plen)
return plen, headLength, gen.TCPHandlerStatusOK
}
log.Infof("pid %s handle packet: %v", process.Self(), packet)
head := make([]byte, headLength)
copy(head, packet)
code := binary.LittleEndian.Uint32(head)
length := binary.LittleEndian.Uint32(head[4:])
if uint32(plen-headLength) < length {
log.Errorf("packet too short,code is %d cur packet length %d need length %d", code, plen-headLength, length)
return plen - headLength, int(length), gen.TCPHandlerStatusOK
}
body := make([]byte, length)
copy(body, packet[headLength:])
log.Infof("pid %s code: %d length :%d body %s", process.Self(), code, length, string(body))
return plen - headLength - int(length), headLength, gen.TCPHandlerStatusOK
}
I think when packet is not enough(8byte), I will wait next call At this point, I can get the complete data.
But it not,it have next data but first data is lose
from ergo.
e.g
I send a slice -> [3 217 0 0 26 0 0 0 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90]
I send divided into two this slice
3 seconds at intervals
code:
dial.Write(slice[:4])
time.Sleep(time.Second * 3)
dial.Write(slice[4:])
I know that returning a "packet too short" error on the first call
But on the second call, you must receive the complete data after being sent twice.
It is -> [3 217 0 0 26 0 0 0 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90]
but I receive [26 0 0 0 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90]
I lose [3 217 0 0]
That is the data sent for the first time.
from ergo.
You lose the first 4 bytes because of a timeout of socket reading which is 3 seconds by default. To see that, you can add a method HandleTimeout to your object *handle
. The buffer is clearing on this event, that's where you lost these bytes. To fix your example just decrease your sending timeout.
I'm thinking of fixing it by keeping the data in the buffer even timeout is happening.
from ergo.
Thank you. but I have a new question
from ergo.
done in v2.2.3
from ergo.
Related Issues (20)
- GitHub actions fail on all platforms due to integration E2E tests HOT 1
- Unittest `TestDecodeFragment` occasionally fails
- i found rpc:call from erlang to ergo is not working HOT 2
- Ergo receives DIST packet along with the HANDSHAKE final packet. HOT 1
- Second CallRPC method is stuck when it is called against remote erlang node HOT 3
- Does Ergo have a plan to support OTP25/OTP26? HOT 1
- how to use simple_one_for_one under supervisor tree HOT 4
- Panic invalid memory address after reconnect a node HOT 6
- bug for deleteProcess HOT 3
- bug for (*process).UnregisterName HOT 2
- I doubt benchmarks be fair !!! HOT 3
- How to change Logger HOT 2
- When I close it frequently, there will be an unrecoverable panic. HOT 3
- Increase test coverage to 80% HOT 2
- node link problem? How to find HOT 8
- node link problem? HOT 2
- Support for Erlang/OTP 26 HOT 1
- Node.Stop () and node.Wait () will immediately end the process HOT 2
- PoolBehavior does not add restarted process to pool.monitors HOT 1
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 ergo.