Skip to content

Commit 8f375b9

Browse files
committed
Implement several methods around CounterPair struct related to incrementing, reseting and instancing
1 parent a8f4811 commit 8f375b9

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

api.go

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,11 +631,48 @@ func (tcpid *TcpID) NewConnectionInfoFlipped() *ConnectionInfo {
631631
}
632632

633633
type CounterPair struct {
634-
Request uint
635-
Response uint
634+
request uint
635+
response uint
636636
sync.Mutex
637637
}
638638

639+
func (counterPair *CounterPair) IncrementRequest() uint {
640+
counterPair.Lock()
641+
defer counterPair.Unlock()
642+
counterPair.request++
643+
return counterPair.request
644+
}
645+
646+
func (counterPair *CounterPair) IncrementResponse() uint {
647+
counterPair.Lock()
648+
defer counterPair.Unlock()
649+
counterPair.response++
650+
return counterPair.response
651+
}
652+
653+
func (counterPair *CounterPair) ResetRequest() {
654+
counterPair.Lock()
655+
defer counterPair.Unlock()
656+
counterPair.request = 0
657+
}
658+
659+
func (counterPair *CounterPair) ResetResponse() {
660+
counterPair.Lock()
661+
defer counterPair.Unlock()
662+
counterPair.response = 0
663+
}
664+
665+
func (counterPair *CounterPair) Reset() {
666+
counterPair.Lock()
667+
defer counterPair.Unlock()
668+
counterPair.request = 0
669+
counterPair.response = 0
670+
}
671+
672+
func NewCounterPair() *CounterPair {
673+
return &CounterPair{}
674+
}
675+
639676
type GenericMessage struct {
640677
IsRequest bool
641678
CaptureTime time.Time

0 commit comments

Comments
 (0)