Skip to content

Commit faeaff3

Browse files
committed
Enhance NewInt64CounterPacketConn to support separate read and write packet counters
1 parent 586b12c commit faeaff3

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

common/bufio/counter_packet_conn.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,27 @@ type CounterPacketConn struct {
1414
writeCounter []N.CountFunc
1515
}
1616

17-
func NewInt64CounterPacketConn(conn N.PacketConn, readCounter []*atomic.Int64, writeCounter []*atomic.Int64) *CounterPacketConn {
17+
func NewInt64CounterPacketConn(conn N.PacketConn, readCounter []*atomic.Int64, readPacketCounter []*atomic.Int64, writeCounter []*atomic.Int64, writePacketCounter []*atomic.Int64) *CounterPacketConn {
1818
return &CounterPacketConn{
1919
conn,
20-
common.Map(readCounter, func(it *atomic.Int64) N.CountFunc {
20+
append(common.Map(readCounter, func(it *atomic.Int64) N.CountFunc {
2121
return func(n int64) {
2222
it.Add(n)
2323
}
24-
}),
25-
common.Map(writeCounter, func(it *atomic.Int64) N.CountFunc {
24+
}), common.Map(readPacketCounter, func(it *atomic.Int64) N.CountFunc {
25+
return func(n int64) {
26+
it.Add(1)
27+
}
28+
})...),
29+
append(common.Map(writeCounter, func(it *atomic.Int64) N.CountFunc {
2630
return func(n int64) {
2731
it.Add(n)
2832
}
29-
}),
33+
}), common.Map(writePacketCounter, func(it *atomic.Int64) N.CountFunc {
34+
return func(n int64) {
35+
it.Add(1)
36+
}
37+
})...),
3038
}
3139
}
3240

0 commit comments

Comments
 (0)