github.com/Uhtred009/v2ray-core-1@v4.31.2+incompatible/transport/internet/connection.go (about) 1 package internet 2 3 import ( 4 "net" 5 6 "v2ray.com/core/features/stats" 7 ) 8 9 type Connection interface { 10 net.Conn 11 } 12 13 type StatCouterConnection struct { 14 Connection 15 ReadCounter stats.Counter 16 WriteCounter stats.Counter 17 } 18 19 func (c *StatCouterConnection) Read(b []byte) (int, error) { 20 nBytes, err := c.Connection.Read(b) 21 if c.ReadCounter != nil { 22 c.ReadCounter.Add(int64(nBytes)) 23 } 24 25 return nBytes, err 26 } 27 28 func (c *StatCouterConnection) Write(b []byte) (int, error) { 29 nBytes, err := c.Connection.Write(b) 30 if c.WriteCounter != nil { 31 c.WriteCounter.Add(int64(nBytes)) 32 } 33 return nBytes, err 34 }