1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-30 05:56:54 -05:00

simplify code

This commit is contained in:
V2Ray 2015-09-22 18:31:06 +02:00
parent ec83281d18
commit f30841019d
2 changed files with 13 additions and 18 deletions

View File

@ -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()
}

View File

@ -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)
}