把Tunnel中的错误处理单独用一个函数做
This commit is contained in:
@@ -69,26 +69,44 @@ func (this *Tunnel) Run() { //单向的,从src发送到dest
|
||||
|
||||
}
|
||||
|
||||
func (this *Tunnel) receive(revCarrier *tscipher.Carrier) {
|
||||
func (this *Tunnel) onError() {
|
||||
src := this.src
|
||||
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
|
||||
id := this.id
|
||||
defer func() {
|
||||
//注销
|
||||
if !this.unregistered { // 应该不存在异步问题
|
||||
this.unregChan <- this
|
||||
this.unregistered = true
|
||||
}
|
||||
if r := recover(); r != nil {
|
||||
if src != nil {
|
||||
src.Close()
|
||||
}
|
||||
if dest != nil {
|
||||
dest.Close()
|
||||
}
|
||||
}
|
||||
}()
|
||||
defer this.onError()
|
||||
// defer func() {
|
||||
// //注销
|
||||
// if !this.unregistered { // 应该不存在异步问题
|
||||
// this.unregChan <- this
|
||||
// this.unregistered = true
|
||||
// }
|
||||
// if r := recover(); r != nil {
|
||||
// if src != nil {
|
||||
// src.Close()
|
||||
// }
|
||||
// if dest != nil {
|
||||
// dest.Close()
|
||||
// }
|
||||
// }
|
||||
// }()
|
||||
var n int
|
||||
var err error
|
||||
for {
|
||||
@@ -108,25 +126,10 @@ func (this *Tunnel) receive(revCarrier *tscipher.Carrier) {
|
||||
}
|
||||
|
||||
func (this *Tunnel) send(sendCarrier *tscipher.Carrier) {
|
||||
src := this.src
|
||||
dest := this.dest
|
||||
cipherDirection := this.cipherDirection
|
||||
id := this.id
|
||||
defer func() {
|
||||
//注销
|
||||
if !this.unregistered {
|
||||
this.unregChan <- this
|
||||
this.unregistered = true
|
||||
}
|
||||
if r := recover(); r != nil {
|
||||
if src != nil {
|
||||
src.Close()
|
||||
}
|
||||
if dest != nil {
|
||||
dest.Close()
|
||||
}
|
||||
}
|
||||
}()
|
||||
defer this.onError()
|
||||
if cipherDirection != constant.SEND {
|
||||
sendCarrier.Cipher = nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user