1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 01:57:12 -05:00
v2fly/transport/internet/connection.go
2022-01-02 15:16:23 +00:00

35 lines
610 B
Go

package internet
import (
"net"
"github.com/v2fly/v2ray-core/v5/features/stats"
)
type Connection interface {
net.Conn
}
type StatCouterConnection struct {
Connection
ReadCounter stats.Counter
WriteCounter stats.Counter
}
func (c *StatCouterConnection) Read(b []byte) (int, error) {
nBytes, err := c.Connection.Read(b)
if c.ReadCounter != nil {
c.ReadCounter.Add(int64(nBytes))
}
return nBytes, err
}
func (c *StatCouterConnection) Write(b []byte) (int, error) {
nBytes, err := c.Connection.Write(b)
if c.WriteCounter != nil {
c.WriteCounter.Add(int64(nBytes))
}
return nBytes, err
}