github.com/arieschain/arieschain@v0.0.0-20191023063405-37c074544356/rpc/ipc_unix.go (about)

     1  // +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris
     2  
     3  package rpc
     4  
     5  import (
     6  	"context"
     7  	"net"
     8  	"os"
     9  	"path/filepath"
    10  )
    11  
    12  // ipcListen will create a Unix socket on the given endpoint.
    13  func ipcListen(endpoint string) (net.Listener, error) {
    14  	// Ensure the IPC path exists and remove any previous leftover
    15  	if err := os.MkdirAll(filepath.Dir(endpoint), 0751); err != nil {
    16  		return nil, err
    17  	}
    18  	os.Remove(endpoint)
    19  	l, err := net.Listen("unix", endpoint)
    20  	if err != nil {
    21  		return nil, err
    22  	}
    23  	os.Chmod(endpoint, 0600)
    24  	return l, nil
    25  }
    26  
    27  // newIPCConnection will connect to a Unix socket on the given endpoint.
    28  func newIPCConnection(ctx context.Context, endpoint string) (net.Conn, error) {
    29  	return dialContext(ctx, "unix", endpoint)
    30  }