0e96f602fa
matcher: fix IPv6 normalization via netip.ParseAddr, port-range overwrite by switching to []*PortRange map, case-insensitive domain/host matching, glob.MustCompile→Compile to avoid panic on invalid patterns. plugin: guard nil *Options in NewGRPCConn and NewHTTPClient; add HTTPClientTransport helper for idle-connection cleanup. net/*: add doc comments for all exported symbols (no code changes). Add 30 tests (matcher_test.go 22, plugin_test.go 8) covering all matcher types, nil safety, case insensitivity, IPv6 normalization, port ranges, and plugin option composition.
41 lines
846 B
Go
41 lines
846 B
Go
package net
|
|
|
|
import (
|
|
"io"
|
|
|
|
"github.com/go-gost/core/common/bufpool"
|
|
)
|
|
|
|
const (
|
|
bufferSize = 64 * 1024
|
|
)
|
|
|
|
// Transport copies data bidirectionally between rw1 and rw2 using two
|
|
// goroutines. It returns the first non-EOF error encountered.
|
|
func Transport(rw1, rw2 io.ReadWriter) error {
|
|
errc := make(chan error, 2)
|
|
go func() {
|
|
errc <- CopyBuffer(rw1, rw2, bufferSize)
|
|
}()
|
|
|
|
go func() {
|
|
errc <- CopyBuffer(rw2, rw1, bufferSize)
|
|
}()
|
|
|
|
if err := <-errc; err != nil && err != io.EOF {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CopyBuffer copies from src to dst using a buffer of bufSize obtained from
|
|
// the buffer pool, reducing allocation overhead for repeated copies.
|
|
func CopyBuffer(dst io.Writer, src io.Reader, bufSize int) error {
|
|
buf := bufpool.Get(bufSize)
|
|
defer bufpool.Put(buf)
|
|
|
|
_, err := io.CopyBuffer(dst, src, buf)
|
|
return err
|
|
}
|