David K. Bainbridge | 215e024 | 2017-09-05 23:18:24 -0700 | [diff] [blame] | 1 | // +build !windows |
| 2 | |
| 3 | package sockets |
| 4 | |
| 5 | import ( |
| 6 | "fmt" |
| 7 | "net" |
| 8 | "net/http" |
| 9 | "syscall" |
| 10 | "time" |
| 11 | ) |
| 12 | |
| 13 | const maxUnixSocketPathSize = len(syscall.RawSockaddrUnix{}.Path) |
| 14 | |
| 15 | func configureUnixTransport(tr *http.Transport, proto, addr string) error { |
| 16 | if len(addr) > maxUnixSocketPathSize { |
| 17 | return fmt.Errorf("Unix socket path %q is too long", addr) |
| 18 | } |
| 19 | // No need for compression in local communications. |
| 20 | tr.DisableCompression = true |
| 21 | tr.Dial = func(_, _ string) (net.Conn, error) { |
| 22 | return net.DialTimeout(proto, addr, defaultTimeout) |
| 23 | } |
| 24 | return nil |
| 25 | } |
| 26 | |
| 27 | func configureNpipeTransport(tr *http.Transport, proto, addr string) error { |
| 28 | return ErrProtocolNotAvailable |
| 29 | } |
| 30 | |
| 31 | // DialPipe connects to a Windows named pipe. |
| 32 | // This is not supported on other OSes. |
| 33 | func DialPipe(_ string, _ time.Duration) (net.Conn, error) { |
| 34 | return nil, syscall.EAFNOSUPPORT |
| 35 | } |