mirror of
https://github.com/lwch/natpass
synced 2025-10-06 13:57:16 +08:00
客户端增加recover
This commit is contained in:
@@ -3,6 +3,7 @@ package pool
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"natpass/code/network"
|
"natpass/code/network"
|
||||||
|
"natpass/code/utils"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@@ -86,6 +87,7 @@ func (conn *Conn) Close() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (conn *Conn) loopRead(cancel context.CancelFunc) {
|
func (conn *Conn) loopRead(cancel context.CancelFunc) {
|
||||||
|
defer utils.Recover("loopRead")
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
var timeout int
|
var timeout int
|
||||||
@@ -128,6 +130,7 @@ func (conn *Conn) loopRead(cancel context.CancelFunc) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (conn *Conn) loopWrite(cancel context.CancelFunc) {
|
func (conn *Conn) loopWrite(cancel context.CancelFunc) {
|
||||||
|
defer utils.Recover("loopWrite")
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
for {
|
for {
|
||||||
@@ -158,6 +161,7 @@ func (conn *Conn) ChanUnknown() <-chan *network.Msg {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (conn *Conn) keepalive(ctx context.Context) {
|
func (conn *Conn) keepalive(ctx context.Context) {
|
||||||
|
defer utils.Recover("keepalive")
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
|
@@ -5,6 +5,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"natpass/code/client/pool"
|
"natpass/code/client/pool"
|
||||||
"natpass/code/network"
|
"natpass/code/network"
|
||||||
|
"natpass/code/utils"
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
"github.com/lwch/logging"
|
"github.com/lwch/logging"
|
||||||
@@ -48,6 +49,7 @@ func (link *Link) Forward() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (link *Link) remoteRead() {
|
func (link *Link) remoteRead() {
|
||||||
|
defer utils.Recover("remoteRead")
|
||||||
defer link.close()
|
defer link.close()
|
||||||
ch := link.remote.ChanRead(link.id)
|
ch := link.remote.ChanRead(link.id)
|
||||||
for {
|
for {
|
||||||
@@ -81,6 +83,7 @@ func (link *Link) remoteRead() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (link *Link) localRead() {
|
func (link *Link) localRead() {
|
||||||
|
defer utils.Recover("localRead")
|
||||||
defer link.close()
|
defer link.close()
|
||||||
<-link.OnWork
|
<-link.OnWork
|
||||||
buf := make([]byte, 16*1024)
|
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