mirror of
https://github.com/Gouryella/drip.git
synced 2026-02-26 22:31:35 +00:00
- Introduce pooled tunnel sessions (TunnelID/DataConnect) on client/server - Proxy HTTP/HTTPS via raw HTTP over yamux streams; pipe TCP streams directly - Move UI/stats into internal/shared; refactor CLI tunnel helpers; drop msgpack/hpack legacy
36 lines
695 B
Go
36 lines
695 B
Go
package netutil
|
|
|
|
import "net"
|
|
|
|
// CountingConn wraps a net.Conn to count bytes read/written.
|
|
type CountingConn struct {
|
|
net.Conn
|
|
OnRead func(int64)
|
|
OnWrite func(int64)
|
|
}
|
|
|
|
// NewCountingConn creates a new CountingConn.
|
|
func NewCountingConn(conn net.Conn, onRead, onWrite func(int64)) *CountingConn {
|
|
return &CountingConn{
|
|
Conn: conn,
|
|
OnRead: onRead,
|
|
OnWrite: onWrite,
|
|
}
|
|
}
|
|
|
|
func (c *CountingConn) Read(p []byte) (int, error) {
|
|
n, err := c.Conn.Read(p)
|
|
if n > 0 && c.OnRead != nil {
|
|
c.OnRead(int64(n))
|
|
}
|
|
return n, err
|
|
}
|
|
|
|
func (c *CountingConn) Write(p []byte) (int, error) {
|
|
n, err := c.Conn.Write(p)
|
|
if n > 0 && c.OnWrite != nil {
|
|
c.OnWrite(int64(n))
|
|
}
|
|
return n, err
|
|
}
|