Minor cleanup of GRPC connection functions.
This commit is contained in:
parent
9f0aba0f32
commit
3858f7f23a
@ -36,16 +36,19 @@ func (s *GRPCServer) Close() {
|
||||
s.server.Stop()
|
||||
}
|
||||
|
||||
// Verifies the RPC UNIX path is still listening if it exists.
|
||||
func RPCCleanPath(rpcPath string) {
|
||||
// Check if the RPC socket already exists.
|
||||
_, err := os.Stat(rpcPath)
|
||||
if err == nil {
|
||||
// If the socket exists, see if its listening.
|
||||
_, err = net.Dial("unix", rpcPath)
|
||||
l, err := net.Dial("unix", rpcPath)
|
||||
|
||||
// If its not listening, remove it to allow us to start.
|
||||
if err != nil {
|
||||
os.Remove(rpcPath)
|
||||
} else {
|
||||
l.Close()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,25 +38,25 @@ func (s *GRPCServer) Close() {
|
||||
s.server.Stop()
|
||||
}
|
||||
|
||||
// Dialer for named pipes to allow connecting GRPC via named pipes.
|
||||
func pipeDialer(ctx context.Context, addr string) (net.Conn, error) {
|
||||
// The addr argument passed by gRPC will be the string we pass to grpc.DialContext (e.g., namedPipePath).
|
||||
// winio.DialPipe handles connecting to the named pipe and returns a net.Conn.
|
||||
// You may need to use winio.DialPipeContext for a cancellable context, but DialPipe
|
||||
// is simpler for a basic example and relies on the deadline set by the gRPC call.
|
||||
return winio.DialPipe(addr, nil)
|
||||
}
|
||||
|
||||
// Verifies the RPC UNIX path is still listening if it exists.
|
||||
func RPCCleanPath(rpcPath string) {
|
||||
if !strings.HasPrefix(rpcPath, `\\.\`) {
|
||||
// Check if the RPC socket already exists.
|
||||
_, err := os.Stat(rpcPath)
|
||||
if err == nil {
|
||||
// If the socket exists, see if its listening.
|
||||
_, err = net.Dial("unix", rpcPath)
|
||||
l, err := net.Dial("unix", rpcPath)
|
||||
|
||||
// If its not listening, remove it to allow us to start.
|
||||
if err != nil {
|
||||
os.Remove(rpcPath)
|
||||
} else {
|
||||
l.Close()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -102,6 +102,7 @@ func NewGRPCClient() (c pb.VxlanClient, conn *grpc.ClientConn, err error) {
|
||||
|
||||
// Start an gRPC client connection to the unix socket.
|
||||
if strings.HasPrefix(config.RPCPath, `\\.\`) {
|
||||
// Attempt to connect using named pipes.
|
||||
dialOption := grpc.WithContextDialer(pipeDialer)
|
||||
|
||||
conn, err = grpc.DialContext(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user