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

fix data race in tcp server

This commit is contained in:
Darien Raymond 2017-10-20 23:36:14 +02:00
parent 85a544d671
commit 1c29d1535c

View File

@ -12,7 +12,6 @@ type Server struct {
MsgProcessor func(msg []byte) []byte
SendFirst []byte
Listen net.Address
accepting bool
listener *net.TCPListener
}
@ -37,12 +36,11 @@ func (server *Server) Start() (net.Destination, error) {
}
func (server *Server) acceptConnections(listener *net.TCPListener) {
server.accepting = true
for server.accepting {
for {
conn, err := listener.Accept()
if err != nil {
fmt.Printf("Failed accept TCP connection: %v\n", err)
continue
return
}
go server.handleConnection(conn)
@ -71,7 +69,6 @@ func (server *Server) handleConnection(conn net.Conn) {
conn.Close()
}
func (v *Server) Close() {
v.accepting = false
v.listener.Close()
func (server *Server) Close() {
server.listener.Close()
}