File tree Expand file tree Collapse file tree 1 file changed +10
-0
lines changed
Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change 2121package bufconn
2222
2323import (
24+ "context"
2425 "fmt"
2526 "io"
2627 "net"
@@ -86,8 +87,17 @@ func (l *Listener) Addr() net.Addr { return addr{} }
8687// providing it the server half of the connection, and returns the client half
8788// of the connection.
8889func (l * Listener ) Dial () (net.Conn , error ) {
90+ return l .DialContext (context .Background ())
91+ }
92+
93+ // DialContext creates an in-memory full-duplex network connection, unblocks Accept by
94+ // providing it the server half of the connection, and returns the client half
95+ // of the connection. If ctx is Done, returns ctx.Err()
96+ func (l * Listener ) DialContext (ctx context.Context ) (net.Conn , error ) {
8997 p1 , p2 := newPipe (l .sz ), newPipe (l .sz )
9098 select {
99+ case <- ctx .Done ():
100+ return nil , ctx .Err ()
91101 case <- l .done :
92102 return nil , errClosed
93103 case l .ch <- & conn {p1 , p2 }:
You can’t perform that action at this time.
0 commit comments