mirror of
https://github.com/whyvl/wireproxy.git
synced 2025-04-29 19:01:42 +02:00
simplify connForward
This commit is contained in:
parent
ca9e5ddb44
commit
b77da8ec20
1 changed files with 5 additions and 11 deletions
16
main.go
16
main.go
|
@ -7,6 +7,7 @@ import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
|
@ -266,17 +267,10 @@ func (c CredentialValidator) Valid(username, password string) bool {
|
||||||
|
|
||||||
func connForward(bufSize int, from, to net.Conn) {
|
func connForward(bufSize int, from, to net.Conn) {
|
||||||
buf := make([]byte, bufSize)
|
buf := make([]byte, bufSize)
|
||||||
for {
|
_, err := io.CopyBuffer(to, from, buf)
|
||||||
size, err := from.Read(buf)
|
if err != nil {
|
||||||
if err != nil {
|
to.Close()
|
||||||
to.Close()
|
return
|
||||||
return
|
|
||||||
}
|
|
||||||
_, err = to.Write(buf[:size])
|
|
||||||
if err != nil {
|
|
||||||
to.Close()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue