-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #262 from cfergeau/bsd
Refactor transport.Listen code
- Loading branch information
Showing
8 changed files
with
66 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package transport | ||
|
||
import ( | ||
"errors" | ||
"net" | ||
"net/url" | ||
) | ||
|
||
func defaultListenURL(url *url.URL) (net.Listener, error) { | ||
switch url.Scheme { | ||
case "unix": | ||
return net.Listen(url.Scheme, url.Path) | ||
case "tcp": | ||
return net.Listen("tcp", url.Host) | ||
default: | ||
return nil, errors.New("unexpected scheme") | ||
} | ||
} | ||
|
||
func Listen(endpoint string) (net.Listener, error) { | ||
parsed, err := url.Parse(endpoint) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return listenURL(parsed) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//go:build !darwin && !linux && !windows | ||
// +build !darwin,!linux,!windows | ||
|
||
package transport | ||
|
||
import ( | ||
"net" | ||
"net/url" | ||
) | ||
|
||
func listenURL(url *url.URL) (net.Listener, error) { | ||
return defaultListenURL(url) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
pkg/transport/unixgram_unix.go → pkg/transport/unixgram_darwin.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
//go:build !windows | ||
// +build !windows | ||
//go:build darwin | ||
// +build darwin | ||
|
||
package transport | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
//go:build !darwin | ||
// +build !darwin | ||
|
||
package transport | ||
|
||
import ( | ||
"errors" | ||
"net" | ||
) | ||
|
||
func ListenUnixgram(_ string) (net.Conn, error) { | ||
return nil, errors.New("unsupported 'unixgram' scheme") | ||
} | ||
|
||
func AcceptVfkit(_ net.Conn) (net.Conn, error) { | ||
return nil, errors.New("vfkit is unsupported on this platform") | ||
} |