-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
listener.go
41 lines (33 loc) · 1.15 KB
/
listener.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.
package apiimpl
import (
"fmt"
"net"
"strconv"
"github.com/DataDog/datadog-agent/pkg/config"
)
// getIPCAddressPort returns a listening connection
func getIPCAddressPort() (string, error) {
address, err := config.GetIPCAddress()
if err != nil {
return "", err
}
return fmt.Sprintf("%v:%v", address, config.Datadog.GetInt("cmd_port")), nil
}
// getListener returns a listening connection
func getListener(address string) (net.Listener, error) {
return net.Listen("tcp", address)
}
// returns whether the IPC server is enabled, and if so its host and host:port
func getIPCServerAddressPort() (string, string, bool) {
ipcServerPort := config.Datadog.GetInt("agent_ipc.port")
if ipcServerPort == 0 {
return "", "", false
}
ipcServerHost := config.Datadog.GetString("agent_ipc.host")
ipcServerHostPort := net.JoinHostPort(ipcServerHost, strconv.Itoa(ipcServerPort))
return ipcServerHost, ipcServerHostPort, true
}