把Tunnel中的错误处理单独用一个函数做
This commit is contained in:
parent
1e61d0d9eb
commit
97edfb5fff
|
|
@ -69,26 +69,44 @@ func (this *Tunnel) Run() { //单向的,从src发送到dest
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Tunnel) receive(revCarrier *tscipher.Carrier) {
|
func (this *Tunnel) onError() {
|
||||||
src := this.src
|
src := this.src
|
||||||
dest := this.dest
|
dest := this.dest
|
||||||
|
//注销
|
||||||
|
if !this.unregistered { // 应该不存在异步问题
|
||||||
|
this.unregChan <- this
|
||||||
|
this.unregistered = true
|
||||||
|
}
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
if src != nil {
|
||||||
|
src.Close()
|
||||||
|
}
|
||||||
|
if dest != nil {
|
||||||
|
dest.Close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *Tunnel) receive(revCarrier *tscipher.Carrier) {
|
||||||
|
src := this.src
|
||||||
cipherDirection := this.cipherDirection
|
cipherDirection := this.cipherDirection
|
||||||
id := this.id
|
id := this.id
|
||||||
defer func() {
|
defer this.onError()
|
||||||
//注销
|
// defer func() {
|
||||||
if !this.unregistered { // 应该不存在异步问题
|
// //注销
|
||||||
this.unregChan <- this
|
// if !this.unregistered { // 应该不存在异步问题
|
||||||
this.unregistered = true
|
// this.unregChan <- this
|
||||||
}
|
// this.unregistered = true
|
||||||
if r := recover(); r != nil {
|
// }
|
||||||
if src != nil {
|
// if r := recover(); r != nil {
|
||||||
src.Close()
|
// if src != nil {
|
||||||
}
|
// src.Close()
|
||||||
if dest != nil {
|
// }
|
||||||
dest.Close()
|
// if dest != nil {
|
||||||
}
|
// dest.Close()
|
||||||
}
|
// }
|
||||||
}()
|
// }
|
||||||
|
// }()
|
||||||
var n int
|
var n int
|
||||||
var err error
|
var err error
|
||||||
for {
|
for {
|
||||||
|
|
@ -108,25 +126,10 @@ func (this *Tunnel) receive(revCarrier *tscipher.Carrier) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Tunnel) send(sendCarrier *tscipher.Carrier) {
|
func (this *Tunnel) send(sendCarrier *tscipher.Carrier) {
|
||||||
src := this.src
|
|
||||||
dest := this.dest
|
dest := this.dest
|
||||||
cipherDirection := this.cipherDirection
|
cipherDirection := this.cipherDirection
|
||||||
id := this.id
|
id := this.id
|
||||||
defer func() {
|
defer this.onError()
|
||||||
//注销
|
|
||||||
if !this.unregistered {
|
|
||||||
this.unregChan <- this
|
|
||||||
this.unregistered = true
|
|
||||||
}
|
|
||||||
if r := recover(); r != nil {
|
|
||||||
if src != nil {
|
|
||||||
src.Close()
|
|
||||||
}
|
|
||||||
if dest != nil {
|
|
||||||
dest.Close()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
if cipherDirection != constant.SEND {
|
if cipherDirection != constant.SEND {
|
||||||
sendCarrier.Cipher = nil
|
sendCarrier.Cipher = nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ func (this *TunnelStatusManager) unregister(t interface{}) {
|
||||||
this.mux.Lock()
|
this.mux.Lock()
|
||||||
defer this.mux.Unlock()
|
defer this.mux.Unlock()
|
||||||
l := this.tunnelList
|
l := this.tunnelList
|
||||||
log.Debug("%d tunnels before remove.", this.tunnelList.Len())
|
// log.Debug("%d tunnels before remove.", this.tunnelList.Len())
|
||||||
nl := new(list.List)
|
nl := new(list.List)
|
||||||
for e := l.Front(); e != nil; e = e.Next() {
|
for e := l.Front(); e != nil; e = e.Next() {
|
||||||
if e.Value != t {
|
if e.Value != t {
|
||||||
|
|
@ -51,7 +51,7 @@ func (this *TunnelStatusManager) unregister(t interface{}) {
|
||||||
|
|
||||||
}
|
}
|
||||||
this.tunnelList = nl
|
this.tunnelList = nl
|
||||||
log.Debug("%d tunnels after remove.", this.tunnelList.Len())
|
// log.Debug("%d tunnels after remove.", this.tunnelList.Len())
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue