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

test/bufconn: add Listener.DialContext(context.Context) #4763

Merged
merged 1 commit into from Sep 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions test/bufconn/bufconn.go
Expand Up @@ -21,6 +21,7 @@
package bufconn

import (
"context"
"fmt"
"io"
"net"
Expand Down Expand Up @@ -86,8 +87,17 @@ func (l *Listener) Addr() net.Addr { return addr{} }
// providing it the server half of the connection, and returns the client half
// of the connection.
func (l *Listener) Dial() (net.Conn, error) {
return l.DialContext(context.Background())
}

// DialContext creates an in-memory full-duplex network connection, unblocks Accept by
// providing it the server half of the connection, and returns the client half
// of the connection. If ctx is Done, returns ctx.Err()
func (l *Listener) DialContext(ctx context.Context) (net.Conn, error) {
p1, p2 := newPipe(l.sz), newPipe(l.sz)
select {
case <-ctx.Done():
return nil, ctx.Err()
case <-l.done:
return nil, errClosed
case l.ch <- &conn{p1, p2}:
Expand Down