mirror of
https://github.com/BishopFox/sliver
synced 2026-06-08 10:29:05 +00:00
bdf4a6ed0d
Co-authored-by: Codex
27 lines
562 B
Go
27 lines
562 B
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
|
|
"google.golang.org/grpc"
|
|
"google.golang.org/grpc/connectivity"
|
|
)
|
|
|
|
func handleConnectionLost(ln *grpc.ClientConn) {
|
|
if ln == nil {
|
|
return
|
|
}
|
|
currentState := ln.GetState()
|
|
// currentState should be "Ready" when the connection is established.
|
|
if ln.WaitForStateChange(context.Background(), currentState) {
|
|
newState := ln.GetState()
|
|
// newState will be "Idle" if the connection is lost.
|
|
if newState == connectivity.Idle {
|
|
fmt.Println("\nLost connection to server. Exiting now.")
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
}
|