Read 1024 Bytes a time of stream; more time-precise stats

This commit is contained in:
maride 2017-09-28 23:31:10 +02:00
parent ba769a8435
commit f1ec646068

View File

@ -188,12 +188,17 @@ func proxy(c net.Conn) {
fmt.Println("[ERR] Proxy connection to server failed")
fmt.Println(" Error is ", err)
} else {
// A bit of cluttery code for statistics purposes, sorry.
go func() {
delta_traffic_in, _ := io.Copy(c, ln)
traffic_in += delta_traffic_in
}()
delta_traffic_out, _ := io.Copy(ln, c)
traffic_out += delta_traffic_out
go proxy_writefunc(c, ln, &traffic_in)
proxy_writefunc(ln, c, &traffic_out)
}
}
func proxy_writefunc(a net.Conn, b net.Conn, written_bytes *int64) {
var delta int64 = 0
var err error
for err == nil {
delta, err = io.CopyN(a, b, 1024)
*written_bytes += delta
}
}