Fix data loss on TCP reconnect:
1. Fixed ByteFIFO (fifo.go): Changed Dequeue(), DequeueOrWait(), and DequeueOrWaitContext() to always copy() data into a new byte slice instead of just slicing the buffer. 2. Fixed TCP server logic (tcpserver.go): Changed the send goroutine to poll for data availability (without dequeueing) using GetLen(), then sleep briefly to batch incoming data, and finally dequeue all available data at once. This avoids the race condition where we were splitting dequeue operations and losing bytes in between.
This commit is contained in:
1
ptc.go
1
ptc.go
@@ -392,6 +392,7 @@ func (p *Modem) modemThread() {
|
||||
writeDebug("response: "+string(res)+"\n"+hex.Dump(res), 3)
|
||||
switch c {
|
||||
case PactorChannel:
|
||||
writeDebug(fmt.Sprintf("Modem received %d bytes from PACTOR, enqueueing to Data.Response: %s", len(res), hex.EncodeToString(res)), 1)
|
||||
err := s.Data.Response.Enqueue(res)
|
||||
if err != nil {
|
||||
writeDebug(err.Error(), 0)
|
||||
|
||||
Reference in New Issue
Block a user