File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -67,6 +67,8 @@ type Conn struct {
67
67
compressedHeader [7 ]byte
68
68
69
69
compressedReader io.Reader
70
+
71
+ Stats * Stats
70
72
}
71
73
72
74
func NewConn (conn net.Conn ) * Conn {
@@ -274,6 +276,9 @@ func (c *Conn) ReadPacketTo(w io.Writer) error {
274
276
// will modify data inplace
275
277
func (c * Conn ) WritePacket (data []byte ) error {
276
278
length := len (data ) - 4
279
+ if c .Stats != nil {
280
+ c .Stats .AddTxUncompressedSize (uint64 (length ))
281
+ }
277
282
278
283
for length >= MaxPayloadLen {
279
284
data [0 ] = 0xff
@@ -378,6 +383,9 @@ func (c *Conn) writeCompressed(data []byte) (n int, err error) {
378
383
return 0 , err
379
384
}
380
385
386
+ if c .Stats != nil {
387
+ c .Stats .AddTxCompressedSize (uint64 (compressedPacket .Len ()))
388
+ }
381
389
_ , err = c .Write (compressedPacket .Bytes ())
382
390
if err != nil {
383
391
return 0 , err
Original file line number Diff line number Diff line change
1
+ package packet
2
+
3
+ import "sync/atomic"
4
+
5
+ type Stats struct {
6
+ packetTxCompressedSize atomic.Uint64
7
+ packetTxUncompressedSize atomic.Uint64
8
+ }
9
+
10
+ func (p * Stats ) AddTxCompressedSize (size uint64 ) {
11
+ p .packetTxCompressedSize .Add (size )
12
+ }
13
+
14
+ func (p * Stats ) AddTxUncompressedSize (size uint64 ) {
15
+ p .packetTxUncompressedSize .Add (size )
16
+ }
17
+
18
+ func (p * Stats ) GetTxCompressedSize () uint64 {
19
+ return p .packetTxCompressedSize .Load ()
20
+ }
21
+
22
+ func (p * Stats ) GetTxUncompressedSize () uint64 {
23
+ return p .packetTxUncompressedSize .Load ()
24
+ }
You can’t perform that action at this time.
0 commit comments