Skip to content

Commit

Permalink
Fix legacy routes
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Jan 19, 2025
1 parent 4f453e8 commit 7d58f59
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,18 @@ import (

// Deprecated: use RouteConnectionEx instead.
func (r *Router) RouteConnection(ctx context.Context, conn net.Conn, metadata adapter.InboundContext) error {
return r.routeConnection(ctx, conn, metadata, nil)
done := make(chan interface{})
err := r.routeConnection(ctx, conn, metadata, N.OnceClose(func(it error) {
close(done)
}))
if err != nil {
return err
}
select {
case <-done:
case <-r.ctx.Done():
}
return nil
}

func (r *Router) RouteConnectionEx(ctx context.Context, conn net.Conn, metadata adapter.InboundContext, onClose N.CloseHandlerFunc) {
Expand Down Expand Up @@ -141,7 +152,10 @@ func (r *Router) routeConnection(ctx context.Context, conn net.Conn, metadata ad
}

func (r *Router) RoutePacketConnection(ctx context.Context, conn N.PacketConn, metadata adapter.InboundContext) error {
err := r.routePacketConnection(ctx, conn, metadata, nil)
done := make(chan interface{})
err := r.routePacketConnection(ctx, conn, metadata, N.OnceClose(func(it error) {
close(done)
}))
if err != nil {
conn.Close()
if E.IsClosedOrCanceled(err) {
Expand Down

0 comments on commit 7d58f59

Please sign in to comment.