Skip to content

Commit

Permalink
fix(client): wait for interrupt signal to close connection
Browse files Browse the repository at this point in the history
  • Loading branch information
jkuri committed Apr 17, 2018
1 parent b6c2592 commit d0ab23b
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions cmd/vex/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,24 @@ func main() {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)

for {
// Open a (local) connection to localEndpoint whose content will be forwarded so serverEndpoint
local, err := net.Dial("tcp", localEndpoint.String())
if err != nil {
log.Fatalln(fmt.Printf("Dial INTO local service error: %s", err))
}

client, err := listener.Accept()
if err != nil {
log.Fatalln(err)
go func() {
for {
// Open a (local) connection to localEndpoint whose content will be forwarded so serverEndpoint
local, err := net.Dial("tcp", localEndpoint.String())
if err != nil {
log.Fatalln(fmt.Printf("Dial INTO local service error: %s", err))
}

client, err := listener.Accept()
if err != nil {
log.Fatalln(err)
}

go handleClient(client, local)
}
}()

go handleClient(client, local)
}
<-c
}

func handleClient(client net.Conn, remote net.Conn) {
Expand Down

0 comments on commit d0ab23b

Please sign in to comment.