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