|
|
@ -3,7 +3,6 @@ package proxy
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"bytes"
|
|
|
|
"io"
|
|
|
|
"io"
|
|
|
|
"net"
|
|
|
|
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
"strings"
|
|
|
|
"sync"
|
|
|
|
"sync"
|
|
|
@ -40,11 +39,11 @@ func LogErr(log *_log.Entry, err error) (loged bool) {
|
|
|
|
// 转发流量
|
|
|
|
// 转发流量
|
|
|
|
// Read a => Write b
|
|
|
|
// Read a => Write b
|
|
|
|
// Read b => Write a
|
|
|
|
// Read b => Write a
|
|
|
|
func Transfer(log *_log.Entry, a, b io.ReadWriteCloser) {
|
|
|
|
func Transfer(log *_log.Entry, a, b io.ReadWriter) {
|
|
|
|
done := make(chan struct{})
|
|
|
|
done := make(chan struct{})
|
|
|
|
defer close(done)
|
|
|
|
defer close(done)
|
|
|
|
|
|
|
|
|
|
|
|
forward := func(dst io.WriteCloser, src io.Reader, ec chan<- error) {
|
|
|
|
forward := func(dst io.Writer, src io.Reader, ec chan<- error) {
|
|
|
|
_, err := io.Copy(dst, src)
|
|
|
|
_, err := io.Copy(dst, src)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
select {
|
|
|
|
select {
|
|
|
@ -55,12 +54,6 @@ func Transfer(log *_log.Entry, a, b io.ReadWriteCloser) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if dstc, ok := dst.(*net.TCPConn); ok {
|
|
|
|
|
|
|
|
err = dstc.CloseWrite()
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
err = dst.Close()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
select {
|
|
|
|
select {
|
|
|
|
case <-done:
|
|
|
|
case <-done:
|
|
|
|
return
|
|
|
|
return
|
|
|
|