mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
pkg/transport: support listeners on unix sockets
Given unix://<socketname>, NewListener will listen on unix socket <socketname>. This is useful when binding to tcp ports is undesirable (e.g., testing).
This commit is contained in:
parent
eab052d5c4
commit
f2df87f3e4
@ -26,7 +26,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func NewListener(addr string, scheme string, info TLSInfo) (net.Listener, error) {
|
func NewListener(addr string, scheme string, info TLSInfo) (net.Listener, error) {
|
||||||
l, err := net.Listen("tcp", addr)
|
nettype := "tcp"
|
||||||
|
if scheme == "unix" {
|
||||||
|
// unix sockets via unix://laddr
|
||||||
|
nettype = scheme
|
||||||
|
}
|
||||||
|
|
||||||
|
l, err := net.Listen(nettype, addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -241,3 +241,11 @@ func TestTLSInfoConfigFuncs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNewListenerUnixSocket(t *testing.T) {
|
||||||
|
l, err := NewListener("testsocket", "unix", TLSInfo{})
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("error listening on unix socket (%v)", err)
|
||||||
|
}
|
||||||
|
l.Close()
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user