mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-04 12:27:37 +03:00
Refactor error handler
This commit is contained in:
parent
30b5895320
commit
63a57e6e12
3 changed files with 3 additions and 6 deletions
|
@ -100,5 +100,5 @@ func IsTimeout(err error) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Handler interface {
|
type Handler interface {
|
||||||
HandleError(err error)
|
NewError(ctx context.Context, err error)
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,7 +87,7 @@ func (s *Service[T]) NewContextPacket(ctx context.Context, key T, buffer *buf.Bu
|
||||||
go func() {
|
go func() {
|
||||||
err := s.handler.NewPacketConnection(ctx, c, metadata)
|
err := s.handler.NewPacketConnection(ctx, c, metadata)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.handler.HandleError(err)
|
s.handler.NewError(ctx, err)
|
||||||
}
|
}
|
||||||
c.Close()
|
c.Close()
|
||||||
s.nat.Delete(key)
|
s.nat.Delete(key)
|
||||||
|
|
|
@ -19,10 +19,7 @@ import (
|
||||||
N "github.com/sagernet/sing/common/network"
|
N "github.com/sagernet/sing/common/network"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Handler interface {
|
type Handler = N.TCPConnectionHandler
|
||||||
N.TCPConnectionHandler
|
|
||||||
N.UDPConnectionHandler
|
|
||||||
}
|
|
||||||
|
|
||||||
func HandleConnection(ctx context.Context, conn net.Conn, authenticator auth.Authenticator, handler Handler, metadata M.Metadata) error {
|
func HandleConnection(ctx context.Context, conn net.Conn, authenticator auth.Authenticator, handler Handler, metadata M.Metadata) error {
|
||||||
reader := std_bufio.NewReader(conn)
|
reader := std_bufio.NewReader(conn)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue