github.com/google/cadvisor@v0.49.1/container/containerd/pkg/dialer/dialer_unix.go (about)

     1  // Copyright 2017 Google Inc. All Rights Reserved.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  //go:build !windows
    15  // +build !windows
    16  
    17  /*
    18     Copyright The containerd Authors.
    19  
    20     Licensed under the Apache License, Version 2.0 (the "License");
    21     you may not use this file except in compliance with the License.
    22     You may obtain a copy of the License at
    23  
    24         http://www.apache.org/licenses/LICENSE-2.0
    25  
    26     Unless required by applicable law or agreed to in writing, software
    27     distributed under the License is distributed on an "AS IS" BASIS,
    28     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    29     See the License for the specific language governing permissions and
    30     limitations under the License.
    31  */
    32  
    33  package dialer
    34  
    35  import (
    36  	"fmt"
    37  	"net"
    38  	"os"
    39  	"strings"
    40  	"syscall"
    41  	"time"
    42  )
    43  
    44  // DialAddress returns the address with unix:// prepended to the
    45  // provided address
    46  func DialAddress(address string) string {
    47  	return fmt.Sprintf("unix://%s", address)
    48  }
    49  
    50  func isNoent(err error) bool {
    51  	if err != nil {
    52  		if nerr, ok := err.(*net.OpError); ok {
    53  			if serr, ok := nerr.Err.(*os.SyscallError); ok {
    54  				if serr.Err == syscall.ENOENT {
    55  					return true
    56  				}
    57  			}
    58  		}
    59  	}
    60  	return false
    61  }
    62  
    63  func dialer(address string, timeout time.Duration) (net.Conn, error) {
    64  	address = strings.TrimPrefix(address, "unix://")
    65  	return net.DialTimeout("unix", address, timeout)
    66  }