1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 17:46:58 -05:00

refactor code

This commit is contained in:
V2Ray 2015-09-20 21:21:55 +02:00
parent cb16047cf0
commit 145d78b271

View File

@ -31,24 +31,24 @@ func (vconn *FreedomConnection) Start(ray core.OutboundRay) error {
readFinish := make(chan bool) readFinish := make(chan bool)
writeFinish := make(chan bool) writeFinish := make(chan bool)
go vconn.DumpInput(conn, input, writeFinish) go dumpInput(conn, input, writeFinish)
go vconn.DumpOutput(conn, output, readFinish) go dumpOutput(conn, output, readFinish)
go vconn.CloseConn(conn, readFinish, writeFinish) go closeConn(conn, readFinish, writeFinish)
return nil return nil
} }
func (vconn *FreedomConnection) DumpInput(conn net.Conn, input <-chan []byte, finish chan<- bool) { func dumpInput(conn net.Conn, input <-chan []byte, finish chan<- bool) {
v2net.ChanToWriter(conn, input) v2net.ChanToWriter(conn, input)
finish <- true close(finish)
} }
func (vconn *FreedomConnection) DumpOutput(conn net.Conn, output chan<- []byte, finish chan<- bool) { func dumpOutput(conn net.Conn, output chan<- []byte, finish chan<- bool) {
v2net.ReaderToChan(output, conn) v2net.ReaderToChan(output, conn)
close(output) close(output)
finish <- true close(finish)
} }
func (vconn *FreedomConnection) CloseConn(conn net.Conn, readFinish <-chan bool, writeFinish <-chan bool) { func closeConn(conn net.Conn, readFinish <-chan bool, writeFinish <-chan bool) {
<-writeFinish <-writeFinish
if tcpConn, ok := conn.(*net.TCPConn); ok { if tcpConn, ok := conn.(*net.TCPConn); ok {
tcpConn.CloseWrite() tcpConn.CloseWrite()