1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 01:57:12 -05:00

fixes for sync logic

This commit is contained in:
v2ray 2016-01-04 01:19:27 +01:00
parent 4a7f45113a
commit 59a5f832f6
4 changed files with 24 additions and 33 deletions

View File

@ -87,6 +87,7 @@ func (this *DokodemoDoor) handleUDPPackets() {
buffer := alloc.NewBuffer() buffer := alloc.NewBuffer()
this.udpMutex.RLock() this.udpMutex.RLock()
if !this.accepting { if !this.accepting {
this.udpMutex.RUnlock()
return return
} }
nBytes, addr, err := this.udpConn.ReadFromUDP(buffer.Value) nBytes, addr, err := this.udpConn.ReadFromUDP(buffer.Value)
@ -132,19 +133,17 @@ func (this *DokodemoDoor) ListenTCP(port v2net.Port) error {
func (this *DokodemoDoor) AcceptTCPConnections() { func (this *DokodemoDoor) AcceptTCPConnections() {
for this.accepting { for this.accepting {
retry.Timed(100, 100).On(func() error { retry.Timed(100, 100).On(func() error {
this.tcpMutex.RLock()
defer this.tcpMutex.RUnlock()
if !this.accepting { if !this.accepting {
return nil return nil
} }
this.tcpMutex.RLock()
defer this.tcpMutex.RUnlock()
if this.tcpListener != nil {
connection, err := this.tcpListener.AcceptTCP() connection, err := this.tcpListener.AcceptTCP()
if err != nil { if err != nil {
log.Error("Dokodemo failed to accept new connections: %v", err) log.Error("Dokodemo failed to accept new connections: %v", err)
return err return err
} }
go this.HandleTCPConnection(connection) go this.HandleTCPConnection(connection)
}
return nil return nil
}) })
} }

View File

@ -59,19 +59,17 @@ func (this *HttpProxyServer) Listen(port v2net.Port) error {
func (this *HttpProxyServer) accept() { func (this *HttpProxyServer) accept() {
for this.accepting { for this.accepting {
retry.Timed(100 /* times */, 100 /* ms */).On(func() error { retry.Timed(100 /* times */, 100 /* ms */).On(func() error {
this.Lock()
defer this.Unlock()
if !this.accepting { if !this.accepting {
return nil return nil
} }
this.Lock()
defer this.Unlock()
if this.tcpListener != nil {
tcpConn, err := this.tcpListener.AcceptTCP() tcpConn, err := this.tcpListener.AcceptTCP()
if err != nil { if err != nil {
log.Error("Failed to accept HTTP connection: %v", err) log.Error("Failed to accept HTTP connection: %v", err)
return err return err
} }
go this.handleConnection(tcpConn) go this.handleConnection(tcpConn)
}
return nil return nil
}) })
} }

View File

@ -78,16 +78,12 @@ func (this *SocksServer) Listen(port v2net.Port) error {
func (this *SocksServer) AcceptConnections() { func (this *SocksServer) AcceptConnections() {
for this.accepting { for this.accepting {
retry.Timed(100 /* times */, 100 /* ms */).On(func() error { retry.Timed(100 /* times */, 100 /* ms */).On(func() error {
this.tcpMutex.RLock()
defer this.tcpMutex.RUnlock()
if !this.accepting { if !this.accepting {
return nil return nil
} }
this.tcpMutex.RLock()
if this.tcpListener == nil {
this.tcpMutex.RUnlock()
return nil
}
connection, err := this.tcpListener.AcceptTCP() connection, err := this.tcpListener.AcceptTCP()
this.tcpMutex.RUnlock()
if err != nil { if err != nil {
log.Error("Socks failed to accept new connection %v", err) log.Error("Socks failed to accept new connection %v", err)
return err return err

View File

@ -64,19 +64,17 @@ func (this *VMessInboundHandler) Listen(port v2net.Port) error {
func (this *VMessInboundHandler) AcceptConnections() error { func (this *VMessInboundHandler) AcceptConnections() error {
for this.accepting { for this.accepting {
retry.Timed(100 /* times */, 100 /* ms */).On(func() error { retry.Timed(100 /* times */, 100 /* ms */).On(func() error {
this.Lock()
defer this.Unlock()
if !this.accepting { if !this.accepting {
return nil return nil
} }
this.Lock()
defer this.Unlock()
if this.listener != nil {
connection, err := this.listener.AcceptTCP() connection, err := this.listener.AcceptTCP()
if err != nil { if err != nil {
log.Error("Failed to accpet connection: %s", err.Error()) log.Error("Failed to accpet connection: %s", err.Error())
return err return err
} }
go this.HandleConnection(connection) go this.HandleConnection(connection)
}
return nil return nil
}) })