mirror of
https://github.com/cmz0228/hysteria-dev.git
synced 2025-08-11 20:01:46 +00:00
Implement Prometheus metrics
This commit is contained in:
@@ -8,11 +8,14 @@ import (
|
||||
|
||||
const PipeBufferSize = 65536
|
||||
|
||||
func Pipe(src, dst io.ReadWriter) error {
|
||||
func Pipe(src, dst io.ReadWriter, count func(int)) error {
|
||||
buf := make([]byte, PipeBufferSize)
|
||||
for {
|
||||
rn, err := src.Read(buf)
|
||||
if rn > 0 {
|
||||
if count != nil {
|
||||
count(rn)
|
||||
}
|
||||
_, err := dst.Write(buf[:rn])
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -24,13 +27,20 @@ func Pipe(src, dst io.ReadWriter) error {
|
||||
}
|
||||
}
|
||||
|
||||
func Pipe2Way(rw1, rw2 io.ReadWriter) error {
|
||||
// count: positive numbers for rw1 to rw2, negative numbers for rw2 to re1
|
||||
func Pipe2Way(rw1, rw2 io.ReadWriter, count func(int)) error {
|
||||
errChan := make(chan error, 2)
|
||||
go func() {
|
||||
errChan <- Pipe(rw2, rw1)
|
||||
var revCount func(int)
|
||||
if count != nil {
|
||||
revCount = func(i int) {
|
||||
count(-i)
|
||||
}
|
||||
}
|
||||
errChan <- Pipe(rw2, rw1, revCount)
|
||||
}()
|
||||
go func() {
|
||||
errChan <- Pipe(rw1, rw2)
|
||||
errChan <- Pipe(rw1, rw2, count)
|
||||
}()
|
||||
// We only need the first error
|
||||
return <-errChan
|
||||
|
Reference in New Issue
Block a user