@@ 4,6 4,7 @@
package kgp
import (
+ "time"
"bytes"
"context"
"encoding/binary"
@@ 135,6 136,17 @@ type Demux struct {
RxSize int
TxSize int
+ // Time between keepalive packets, 0 == no keepalive
+ Keepalive time.Duration
+ // Where to write keepalive timings format:
+ //
+ // keepalive 1234ms
+ //
+ // or
+ //
+ // keepalive timeout
+ KeepaliveWriter io.Writer
+
Logger *log.Logger
server io.ReadWriter
@@ 282,7 294,6 @@ func (demux *Demux) readServer(
return
}
ack.Store(p.header.Sequence)
- fmt.Println(ack.Load())
demux.rxBytes += p.Size()
demux.rxPackets += 1
// Send the new packet to output and check if we're done
@@ 353,7 364,7 @@ func (demux *Demux) writeServer(
return input
}
-func keepAlive(
+func keepaliveReply(
done func() <-chan struct{},
p *Packet,
output chan<- *Packet,
@@ 427,7 438,7 @@ func (demux *Demux) Run(ctx context.Cont
}
switch p.Type() {
case keepalivePacket:
- go keepAlive(done, p, output)
+ go keepaliveReply(done, p, output)
case closePacket:
if bytes.Equal(p.Payload, []byte{'r'}) {
// half-close, we'll no longer receive data from the server