diff --git a/proxy/freedom/freedom.go b/proxy/freedom/freedom.go index a2999b54..11f691ad 100644 --- a/proxy/freedom/freedom.go +++ b/proxy/freedom/freedom.go @@ -46,7 +46,13 @@ func (vconn *FreedomConnection) Start(ray core.OutboundRay) error { go dumpInput(conn, input, writeFinish) go dumpOutput(conn, output, readFinish) - go closeConn(conn, readFinish, writeFinish) + + <-writeFinish + if tcpConn, ok := conn.(*net.TCPConn); ok { + tcpConn.CloseWrite() + } + <-readFinish + conn.Close() return nil } @@ -60,12 +66,3 @@ func dumpOutput(conn net.Conn, output chan<- []byte, finish chan<- bool) { close(output) close(finish) } - -func closeConn(conn net.Conn, readFinish <-chan bool, writeFinish <-chan bool) { - <-writeFinish - if tcpConn, ok := conn.(*net.TCPConn); ok { - tcpConn.CloseWrite() - } - <-readFinish - conn.Close() -} diff --git a/proxy/socks/socks.go b/proxy/socks/socks.go index c54c45aa..4237a031 100644 --- a/proxy/socks/socks.go +++ b/proxy/socks/socks.go @@ -176,22 +176,20 @@ func (server *SocksServer) HandleConnection(connection net.Conn) error { readFinish := make(chan bool) writeFinish := make(chan bool) - go server.dumpInput(reader, input, readFinish) - go server.dumpOutput(connection, output, writeFinish) + go dumpInput(reader, input, readFinish) + go dumpOutput(connection, output, writeFinish) <-writeFinish return nil } -func (server *SocksServer) dumpInput(reader io.Reader, input chan<- []byte, finish chan<- bool) { +func dumpInput(reader io.Reader, input chan<- []byte, finish chan<- bool) { v2net.ReaderToChan(input, reader) close(input) - log.Debug("Socks input closed") - finish <- true + close(finish) } -func (server *SocksServer) dumpOutput(writer io.Writer, output <-chan []byte, finish chan<- bool) { +func dumpOutput(writer io.Writer, output <-chan []byte, finish chan<- bool) { v2net.ChanToWriter(writer, output) - log.Debug("Socks output closed") - finish <- true + close(finish) }