1
0
mirror of https://github.com/schollz/croc.git synced 2024-11-24 16:23:47 +03:00

optimize relay

This commit is contained in:
Zack Scholl 2018-09-26 06:35:51 -07:00
parent da2b22f73d
commit 0b3d19a52e

View File

@ -126,19 +126,15 @@ func chanFromConn(conn net.Conn) chan []byte {
c := make(chan []byte)
go func() {
b := make([]byte, models.TCP_BUFFER_SIZE)
for {
n, err := conn.Read(b)
if n > 0 {
res := make([]byte, n)
// Copy the buffer so it doesn't get changed while read by the recipient.
copy(res, b[:n])
c <- res
}
b := make([]byte, models.TCP_BUFFER_SIZE)
_, err := conn.Read(b)
if err != nil {
c <- nil
break
} else {
c <- b
}
}
}()