ZeroTierOne/go/pkg/zerotier/osdep-posix.go

46 lines
1.0 KiB
Go
Raw Normal View History

2019-09-23 15:18:52 -07:00
// +build !windows
/*
* Copyright (c)2019 ZeroTier, Inc.
*
* Use of this software is governed by the Business Source License included
* in the LICENSE.TXT file in the project's root directory.
*
* Change Date: 2023-01-01
*
* On the date above, in accordance with the Business Source License, use
* of this software will be governed by version 2.0 of the Apache License.
*/
/****/
package zerotier
import (
2019-09-24 16:44:29 -07:00
"context"
2019-09-23 15:18:52 -07:00
"net"
2019-09-24 16:44:29 -07:00
"net/http"
2019-09-23 15:18:52 -07:00
"os"
"path"
2019-09-24 16:44:29 -07:00
"time"
2019-09-23 15:18:52 -07:00
)
func createNamedSocketListener(basePath, name string) (net.Listener, error) {
apiSockPath := path.Join(basePath, name)
os.Remove(apiSockPath)
return net.Listen("unix", apiSockPath)
}
2019-09-24 16:44:29 -07:00
func createNamedSocketHTTPClient(basePath, name string) (*http.Client, error) {
apiSockPath := path.Join(basePath, name)
return &http.Client{
Timeout: 10 * time.Second,
Transport: &http.Transport{
DialContext: func(_ context.Context, _, _ string) (net.Conn, error) {
return net.Dial("unix", apiSockPath)
},
DisableKeepAlives: true,
DisableCompression: true,
},
}, nil
}