Skip to content

Commit

Permalink
test/bufconn: add Listener.DialContext(context.Context) (#4763)
Browse files Browse the repository at this point in the history
  • Loading branch information
edwarnicke authored Sep 16, 2021
1 parent 7cf9689 commit b186ee8
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions test/bufconn/bufconn.go
Original file line number Diff line number Diff line change
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

0 comments on commit b186ee8

Please sign in to comment.