1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 09:36:34 -05:00

Fix usage of Mutex

This commit is contained in:
V2Ray 2015-09-23 17:13:50 +02:00
parent 3fbae6795a
commit bb442b4f83
4 changed files with 16 additions and 16 deletions

View File

@ -46,8 +46,8 @@ func (vconn *FreedomConnection) Start(ray core.OutboundRay) error {
readMutex.Lock()
writeMutex.Lock()
go dumpInput(conn, input, writeMutex)
go dumpOutput(conn, output, readMutex)
go dumpInput(conn, input, &writeMutex)
go dumpOutput(conn, output, &readMutex)
go func() {
writeMutex.Lock()
@ -61,12 +61,12 @@ func (vconn *FreedomConnection) Start(ray core.OutboundRay) error {
return nil
}
func dumpInput(conn net.Conn, input <-chan []byte, finish sync.Mutex) {
func dumpInput(conn net.Conn, input <-chan []byte, finish *sync.Mutex) {
v2net.ChanToWriter(conn, input)
finish.Unlock()
}
func dumpOutput(conn net.Conn, output chan<- []byte, finish sync.Mutex) {
func dumpOutput(conn net.Conn, output chan<- []byte, finish *sync.Mutex) {
v2net.ReaderToChan(output, conn)
finish.Unlock()
close(output)

View File

@ -178,20 +178,20 @@ func (server *SocksServer) HandleConnection(connection net.Conn) error {
readFinish.Lock()
writeFinish.Lock()
go dumpInput(reader, input, readFinish)
go dumpOutput(connection, output, writeFinish)
go dumpInput(reader, input, &readFinish)
go dumpOutput(connection, output, &writeFinish)
writeFinish.Lock()
return nil
}
func dumpInput(reader io.Reader, input chan<- []byte, finish sync.Mutex) {
func dumpInput(reader io.Reader, input chan<- []byte, finish *sync.Mutex) {
v2net.ReaderToChan(input, reader)
finish.Unlock()
close(input)
}
func dumpOutput(writer io.Writer, output <-chan []byte, finish sync.Mutex) {
func dumpOutput(writer io.Writer, output <-chan []byte, finish *sync.Mutex) {
v2net.ChanToWriter(writer, output)
finish.Unlock()
}

View File

@ -82,7 +82,7 @@ func (handler *VMessInboundHandler) HandleConnection(connection net.Conn) error
readFinish.Lock()
writeFinish.Lock()
go handleInput(request, connection, input, readFinish)
go handleInput(request, connection, input, &readFinish)
responseKey := md5.Sum(request.RequestKey[:])
responseIV := md5.Sum(request.RequestIV[:])
@ -100,7 +100,7 @@ func (handler *VMessInboundHandler) HandleConnection(connection net.Conn) error
if data, open := <-output; open {
buffer = append(buffer, data...)
responseWriter.Write(buffer)
go handleOutput(request, responseWriter, output, writeFinish)
go handleOutput(request, responseWriter, output, &writeFinish)
writeFinish.Lock()
}
@ -112,7 +112,7 @@ func (handler *VMessInboundHandler) HandleConnection(connection net.Conn) error
return nil
}
func handleInput(request *protocol.VMessRequest, reader io.Reader, input chan<- []byte, finish sync.Mutex) {
func handleInput(request *protocol.VMessRequest, reader io.Reader, input chan<- []byte, finish *sync.Mutex) {
defer close(input)
defer finish.Unlock()
@ -125,7 +125,7 @@ func handleInput(request *protocol.VMessRequest, reader io.Reader, input chan<-
v2net.ReaderToChan(input, requestReader)
}
func handleOutput(request *protocol.VMessRequest, writer io.Writer, output <-chan []byte, finish sync.Mutex) {
func handleOutput(request *protocol.VMessRequest, writer io.Writer, output <-chan []byte, finish *sync.Mutex) {
v2net.ChanToWriter(writer, output)
finish.Unlock()
}

View File

@ -114,8 +114,8 @@ func startCommunicate(request *protocol.VMessRequest, dest v2net.Destination, ra
requestFinish.Lock()
responseFinish.Lock()
go handleRequest(conn, request, input, requestFinish)
go handleResponse(conn, request, output, responseFinish)
go handleRequest(conn, request, input, &requestFinish)
go handleResponse(conn, request, output, &responseFinish)
requestFinish.Lock()
conn.CloseWrite()
@ -123,7 +123,7 @@ func startCommunicate(request *protocol.VMessRequest, dest v2net.Destination, ra
return nil
}
func handleRequest(conn *net.TCPConn, request *protocol.VMessRequest, input <-chan []byte, finish sync.Mutex) {
func handleRequest(conn *net.TCPConn, request *protocol.VMessRequest, input <-chan []byte, finish *sync.Mutex) {
defer finish.Unlock()
encryptRequestWriter, err := v2io.NewAesEncryptWriter(request.RequestKey[:], request.RequestIV[:], conn)
if err != nil {
@ -155,7 +155,7 @@ func handleRequest(conn *net.TCPConn, request *protocol.VMessRequest, input <-ch
return
}
func handleResponse(conn *net.TCPConn, request *protocol.VMessRequest, output chan<- []byte, finish sync.Mutex) {
func handleResponse(conn *net.TCPConn, request *protocol.VMessRequest, output chan<- []byte, finish *sync.Mutex) {
defer finish.Unlock()
defer close(output)
responseKey := md5.Sum(request.RequestKey[:])