Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow network type to be specified #226

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ type ServeConfig struct {
// server will create a default logger.
Logger hclog.Logger

// NetworkType determines what type of network the server will listen on. Valid options are "tcp" and "unix. If
// no NetworkType is specified, the server will default to "tcp" on Windows, and "unix" otherwise.
NetworkType string

// Test, if non-nil, will put plugin serving into "test mode". This is
// meant to be used as part of `go test` within a plugin's codebase to
// launch the plugin in-process and output a ReattachConfig.
Expand Down Expand Up @@ -270,7 +274,7 @@ func Serve(opts *ServeConfig) {
}

// Register a listener so we can accept a connection
listener, err := serverListener()
listener, err := serverListener(opts.NetworkType)
if err != nil {
logger.Error("plugin init error", "error", err)
return
Expand Down Expand Up @@ -493,8 +497,12 @@ func Serve(opts *ServeConfig) {
}
}

func serverListener() (net.Listener, error) {
if runtime.GOOS == "windows" {
func serverListener(networkType string) (net.Listener, error) {
if networkType == "tcp" {
return serverListener_tcp()
} else if networkType == "unix" {
return serverListener_unix()
} else if networkType == "" && runtime.GOOS == "windows" {
return serverListener_tcp()
}

Expand Down