mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-02 07:26:24 -05:00
simplify code
This commit is contained in:
parent
ec83281d18
commit
f30841019d
@ -46,7 +46,13 @@ func (vconn *FreedomConnection) Start(ray core.OutboundRay) error {
|
|||||||
|
|
||||||
go dumpInput(conn, input, writeFinish)
|
go dumpInput(conn, input, writeFinish)
|
||||||
go dumpOutput(conn, output, readFinish)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,12 +66,3 @@ func dumpOutput(conn net.Conn, output chan<- []byte, finish chan<- bool) {
|
|||||||
close(output)
|
close(output)
|
||||||
close(finish)
|
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()
|
|
||||||
}
|
|
||||||
|
@ -176,22 +176,20 @@ func (server *SocksServer) HandleConnection(connection net.Conn) error {
|
|||||||
readFinish := make(chan bool)
|
readFinish := make(chan bool)
|
||||||
writeFinish := make(chan bool)
|
writeFinish := make(chan bool)
|
||||||
|
|
||||||
go server.dumpInput(reader, input, readFinish)
|
go dumpInput(reader, input, readFinish)
|
||||||
go server.dumpOutput(connection, output, writeFinish)
|
go dumpOutput(connection, output, writeFinish)
|
||||||
<-writeFinish
|
<-writeFinish
|
||||||
|
|
||||||
return nil
|
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)
|
v2net.ReaderToChan(input, reader)
|
||||||
close(input)
|
close(input)
|
||||||
log.Debug("Socks input closed")
|
close(finish)
|
||||||
finish <- true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
v2net.ChanToWriter(writer, output)
|
||||||
log.Debug("Socks output closed")
|
close(finish)
|
||||||
finish <- true
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user