aboutsummaryrefslogtreecommitdiff
path: root/pipeln.go
diff options
context:
space:
mode:
authorGrégoire Duchêne <gduchene@awhk.org>2021-06-02 12:25:06 +0100
committerGrégoire Duchêne <gduchene@awhk.org>2021-06-02 12:25:06 +0100
commit94e59f7ec54ad1bddd78c4b385defaa8cff7c15d (patch)
treeb1dc0792036df9c599c2a7a2feb04ec6cce1e2f9 /pipeln.go
parentf06b2f85e8b1158bd63c7ed4d918770626d99545 (diff)
Add a bit more documentation
This mostly redirects people to the standard library documentation as PipeListenerDialer tries to follow the interfaces described there.
Diffstat (limited to 'pipeln.go')
-rw-r--r--pipeln.go15
1 files changed, 12 insertions, 3 deletions
diff --git a/pipeln.go b/pipeln.go
index 29c6523..f085fc3 100644
--- a/pipeln.go
+++ b/pipeln.go
@@ -23,9 +23,8 @@ func (a addr) String() string {
return "pipe:" + a.ln.addr
}
-// PipeListener can be used to simulate client-server interaction within
-// the same process. Useful for testing. Somehow the Go standard library
-// provides net.Pipe but no net.PipeListener.
+// PipeListenerDialer can be used to simulate client-server interaction
+// within the same process.
type PipeListenerDialer struct {
addr string
conns chan net.Conn
@@ -35,6 +34,7 @@ type PipeListenerDialer struct {
var _ net.Listener = &PipeListenerDialer{}
+// See net.Listener.Accept for more details.
func (ln *PipeListenerDialer) Accept() (net.Conn, error) {
select {
case conn := <-ln.conns:
@@ -44,10 +44,12 @@ func (ln *PipeListenerDialer) Accept() (net.Conn, error) {
}
}
+// See net.Listener.Addr for more details.
func (ln *PipeListenerDialer) Addr() net.Addr {
return addr{ln}
}
+// See net.Listener.Close for more details.
func (ln *PipeListenerDialer) Close() error {
if !ln.ok {
return unix.EINVAL
@@ -57,6 +59,7 @@ func (ln *PipeListenerDialer) Close() error {
return nil
}
+// See net.Dialer.Dial for more details.
func (ln *PipeListenerDialer) Dial(_, addr string) (net.Conn, error) {
if addr != ln.addr {
return nil, unix.EINVAL
@@ -70,14 +73,20 @@ func (ln *PipeListenerDialer) Dial(_, addr string) (net.Conn, error) {
}
}
+// DialContext is a dummy wrapper around Dial.
func (ln *PipeListenerDialer) DialContext(_ context.Context, network, addr string) (net.Conn, error) {
return ln.Dial(network, addr)
}
+// DialContextAddr is a dummy wrapper around Dial.
+//
+// This function can be passed to grpc.WithContextDialer.
func (ln *PipeListenerDialer) DialContextAddr(_ context.Context, addr string) (net.Conn, error) {
return ln.Dial("", addr)
}
+// New returns a PipeListenerDialer that will only accept connections
+// made to the given addr.
func New(addr string) *PipeListenerDialer {
return &PipeListenerDialer{addr, make(chan net.Conn), make(chan struct{}), true}
}