osdep-posix.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // +build !windows
  2. /*
  3. * Copyright (C)2013-2020 ZeroTier, Inc.
  4. *
  5. * Use of this software is governed by the Business Source License included
  6. * in the LICENSE.TXT file in the project's root directory.
  7. *
  8. * Change Date: 2025-01-01
  9. *
  10. * On the date above, in accordance with the Business Source License, use
  11. * of this software will be governed by version 2.0 of the Apache License.
  12. */
  13. /****/
  14. package zerotier
  15. import (
  16. "context"
  17. "net"
  18. "net/http"
  19. "os"
  20. "path"
  21. "time"
  22. )
  23. func createNamedSocketListener(basePath, name string) (net.Listener, error) {
  24. apiSockPath := path.Join(basePath, name)
  25. _ = os.Remove(apiSockPath)
  26. return net.Listen("unix", apiSockPath)
  27. }
  28. func createNamedSocketHTTPClient(basePath, name string) (*http.Client, error) {
  29. apiSockPath := path.Join(basePath, name)
  30. return &http.Client{
  31. Timeout: 10 * time.Second,
  32. Transport: &http.Transport{
  33. DialContext: func(_ context.Context, _, _ string) (net.Conn, error) {
  34. return net.Dial("unix", apiSockPath)
  35. },
  36. DisableKeepAlives: true,
  37. DisableCompression: true,
  38. },
  39. }, nil
  40. }