chore: code tidy and doc update

This commit is contained in:
nadoo committed 2022-03-06 12:58:20 +08:00
1 parent 2ad3498abd
commit fc3a21617e
7 files changed
+33 -38

No files matched your search

+9 -5
View File
@@ -178,9 +178,9 @@ func CopyBuffer(dst io.Writer, src io.Reader) (written int64, err error) {
// CopyUDP copys from src to dst at target with read timeout.
// if step sets to non-zero value,
// the read timeout will be increased from 0 to timeout by step in every read operation.
func CopyUDP(dst net.PacketConn, target net.Addr, src net.PacketConn, timeout time.Duration, step time.Duration) error {
b := pool.GetBuffer(UDPBufSize)
defer pool.PutBuffer(b)
func CopyUDP(dst net.PacketConn, writeTo net.Addr, src net.PacketConn, timeout time.Duration, step time.Duration) error {
buf := pool.GetBuffer(UDPBufSize)
defer pool.PutBuffer(buf)
var t time.Duration
for {
@@ -189,12 +189,16 @@ func CopyUDP(dst net.PacketConn, target net.Addr, src net.PacketConn, timeout ti
}
src.SetReadDeadline(time.Now().Add(t))
n, _, err := src.ReadFrom(b)
n, addr, err := src.ReadFrom(buf)
if err != nil {
return err
}
_, err = dst.WriteTo(b[:n], target)
if writeTo != nil {
addr = writeTo
}
_, err = dst.WriteTo(buf[:n], addr)
if err != nil {
return err
}
+1 -2
View File
@@ -1,7 +1,6 @@
package smux
import (
"errors"
"net"
"net/url"
"sync"
@@ -66,7 +65,7 @@ func (s *SmuxClient) Dial(network, addr string) (net.Conn, error) {
// DialUDP connects to the given address via the proxy.
func (s *SmuxClient) DialUDP(network, addr string) (net.PacketConn, net.Addr, error) {
return nil, nil, errors.New("smux client does not support udp now")
return nil, nil, proxy.ErrNotSupported
}
func (s *SmuxClient) initConn() error {