mirror of
https://github.com/nadoo/glider.git
synced 2026-11-19 07:09:42 +08:00
chore: code tidy and doc update
This commit is contained in:
1 parent
2ad3498abd
commit
fc3a21617e
7 files changed
+33
-38
No files matched your search
+9
-5
@@ -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
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user