Skip to content

Commit

Permalink
Merge branch 'feat-proxy-config' of https://github.com/canonical/aproxy
Browse files Browse the repository at this point in the history
… into feat-proxy-config
  • Loading branch information
weiiwang01 committed Apr 1, 2024
2 parents 3f2bcc5 + ae7286e commit 21a77a3
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions aproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ func main() {
log.Fatal(err)
}
listenAddr := *listenFlag
ctx := context.Background()
signal.NotifyContext(ctx, os.Interrupt)
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
defer stop()
listenConfig := new(net.ListenConfig)
listener, err := listenConfig.Listen(ctx, "tcp", listenAddr)
if err != nil {
Expand All @@ -232,12 +232,16 @@ func main() {
} else {
logger.InfoContext(ctx, "start passthrough HTTPS connection")
}
for {
conn, err := listener.Accept()
if err != nil {
logger.ErrorContext(ctx, "failed to accept connection", "error", err)
continue
go func() {
for {
conn, err := listener.Accept()
if err != nil {
logger.ErrorContext(ctx, "failed to accept connection", "error", err)
continue
}
go HandleConn(conn, proxy)
}
go HandleConn(ctx, conn.(*net.TCPConn), forwarder)
}
}()
<-ctx.Done()
stop()
}

0 comments on commit 21a77a3

Please sign in to comment.