From 3858f7f23ab08aa1115198606f0e3adb322cd20a Mon Sep 17 00:00:00 2001 From: GRMrGecko Date: Thu, 23 Oct 2025 11:26:52 -0500 Subject: [PATCH] Minor cleanup of GRPC connection functions. --- grpc_unix.go | 5 ++++- grpc_windows.go | 11 ++++++----- main.go | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/grpc_unix.go b/grpc_unix.go index e5dc86d..e9c0404 100644 --- a/grpc_unix.go +++ b/grpc_unix.go @@ -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() } } } diff --git a/grpc_windows.go b/grpc_windows.go index 682ac4c..1ba94ce 100644 --- a/grpc_windows.go +++ b/grpc_windows.go @@ -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( diff --git a/main.go b/main.go index 33ef03b..004f23a 100644 --- a/main.go +++ b/main.go @@ -6,7 +6,7 @@ const ( serviceDisplayName = "Virtual VXLAN" serviceVendor = "com.mrgeckosmedia" serviceDescription = "Virtual VXLAN using TUN interfaces" - serviceVersion = "0.2.4" + serviceVersion = "0.2.5" defaultConfigFile = "config.yaml" )