github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/juju/sockets/sockets_nix.go (about)

     1  // Copyright 2014 Canonical Ltd.
     2  // Copyright 2014 Cloudbase Solutions SRL
     3  // Licensed under the AGPLv3, see LICENCE file for details.
     4  
     5  // +build !windows
     6  
     7  package sockets
     8  
     9  import (
    10  	"net"
    11  	"net/rpc"
    12  	"os"
    13  
    14  	"github.com/juju/errors"
    15  )
    16  
    17  func Dial(socketPath string) (*rpc.Client, error) {
    18  	return rpc.Dial("unix", socketPath)
    19  }
    20  
    21  func Listen(socketPath string) (net.Listener, error) {
    22  	// In case the unix socket is present, delete it.
    23  	if err := os.Remove(socketPath); err != nil {
    24  		logger.Tracef("ignoring error on removing %q: %v", socketPath, err)
    25  	}
    26  	listener, err := net.Listen("unix", socketPath)
    27  	return listener, errors.Trace(err)
    28  }