mirror of
https://github.com/lwch/natpass
synced 2025-10-06 05:46:49 +08:00
客户端增加recover
This commit is contained in:
@@ -3,6 +3,7 @@ package pool
|
||||
import (
|
||||
"context"
|
||||
"natpass/code/network"
|
||||
"natpass/code/utils"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -86,6 +87,7 @@ func (conn *Conn) Close() {
|
||||
}
|
||||
|
||||
func (conn *Conn) loopRead(cancel context.CancelFunc) {
|
||||
defer utils.Recover("loopRead")
|
||||
defer conn.Close()
|
||||
defer cancel()
|
||||
var timeout int
|
||||
@@ -128,6 +130,7 @@ func (conn *Conn) loopRead(cancel context.CancelFunc) {
|
||||
}
|
||||
|
||||
func (conn *Conn) loopWrite(cancel context.CancelFunc) {
|
||||
defer utils.Recover("loopWrite")
|
||||
defer conn.Close()
|
||||
defer cancel()
|
||||
for {
|
||||
@@ -158,6 +161,7 @@ func (conn *Conn) ChanUnknown() <-chan *network.Msg {
|
||||
}
|
||||
|
||||
func (conn *Conn) keepalive(ctx context.Context) {
|
||||
defer utils.Recover("keepalive")
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
|
@@ -5,6 +5,7 @@ import (
|
||||
"io"
|
||||
"natpass/code/client/pool"
|
||||
"natpass/code/network"
|
||||
"natpass/code/utils"
|
||||
"net"
|
||||
|
||||
"github.com/lwch/logging"
|
||||
@@ -48,6 +49,7 @@ func (link *Link) Forward() {
|
||||
}
|
||||
|
||||
func (link *Link) remoteRead() {
|
||||
defer utils.Recover("remoteRead")
|
||||
defer link.close()
|
||||
ch := link.remote.ChanRead(link.id)
|
||||
for {
|
||||
@@ -81,6 +83,7 @@ func (link *Link) remoteRead() {
|
||||
}
|
||||
|
||||
func (link *Link) localRead() {
|
||||
defer utils.Recover("localRead")
|
||||
defer link.close()
|
||||
<-link.OnWork
|
||||
buf := make([]byte, 16*1024)
|
||||
|
9
code/utils/recover.go
Normal file
9
code/utils/recover.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package utils
|
||||
|
||||
import "github.com/lwch/logging"
|
||||
|
||||
func Recover(name string) {
|
||||
if err := recover(); err != nil {
|
||||
logging.Error("%s: %v", name, err)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user