From 4271e619fe01e12b9bc3ed978f4d4bcc7d4a244d Mon Sep 17 00:00:00 2001 From: v2ray Date: Mon, 4 Jan 2016 08:40:24 +0100 Subject: [PATCH] fixes for mutex usage --- proxy/dokodemo/dokodemo.go | 4 ++++ proxy/socks/socks.go | 2 ++ proxy/socks/udp.go | 2 ++ proxy/vmess/inbound/inbound.go | 2 ++ 4 files changed, 10 insertions(+) diff --git a/proxy/dokodemo/dokodemo.go b/proxy/dokodemo/dokodemo.go index 8276dc4f9..d61781381 100644 --- a/proxy/dokodemo/dokodemo.go +++ b/proxy/dokodemo/dokodemo.go @@ -77,7 +77,9 @@ func (this *DokodemoDoor) ListenUDP(port v2net.Port) error { log.Error("Dokodemo failed to listen on port %d: %v", port, err) return err } + this.udpMutex.Lock() this.udpConn = udpConn + this.udpMutex.Unlock() go this.handleUDPPackets() return nil } @@ -125,7 +127,9 @@ func (this *DokodemoDoor) ListenTCP(port v2net.Port) error { log.Error("Dokodemo failed to listen on port %d: %v", port, err) return err } + this.tcpMutex.Lock() this.tcpListener = tcpListener + this.tcpMutex.Unlock() go this.AcceptTCPConnections() return nil } diff --git a/proxy/socks/socks.go b/proxy/socks/socks.go index 83c3167fe..7ad810c35 100644 --- a/proxy/socks/socks.go +++ b/proxy/socks/socks.go @@ -67,7 +67,9 @@ func (this *SocksServer) Listen(port v2net.Port) error { return err } this.accepting = true + this.tcpMutex.Lock() this.tcpListener = listener + this.tcpMutex.Unlock() go this.AcceptConnections() if this.config.UDPEnabled() { this.ListenUDP(port) diff --git a/proxy/socks/udp.go b/proxy/socks/udp.go index ee69a6740..8ef802346 100644 --- a/proxy/socks/udp.go +++ b/proxy/socks/udp.go @@ -20,8 +20,10 @@ func (this *SocksServer) ListenUDP(port v2net.Port) error { log.Error("Socks failed to listen UDP on port %d: %v", port, err) return err } + this.udpMutex.Lock() this.udpAddress = v2net.UDPDestination(v2net.IPAddress(this.config.IP()), port) this.udpConn = conn + this.udpMutex.Unlock() go this.AcceptPackets() return nil diff --git a/proxy/vmess/inbound/inbound.go b/proxy/vmess/inbound/inbound.go index 40ec829fe..f2d850a51 100644 --- a/proxy/vmess/inbound/inbound.go +++ b/proxy/vmess/inbound/inbound.go @@ -56,7 +56,9 @@ func (this *VMessInboundHandler) Listen(port v2net.Port) error { return err } this.accepting = true + this.Lock() this.listener = listener + this.Unlock() go this.AcceptConnections() return nil }