File tree 1 file changed +10
-0
lines changed
1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change 21
21
package bufconn
22
22
23
23
import (
24
+ "context"
24
25
"fmt"
25
26
"io"
26
27
"net"
@@ -86,8 +87,17 @@ func (l *Listener) Addr() net.Addr { return addr{} }
86
87
// providing it the server half of the connection, and returns the client half
87
88
// of the connection.
88
89
func (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 ) {
89
97
p1 , p2 := newPipe (l .sz ), newPipe (l .sz )
90
98
select {
99
+ case <- ctx .Done ():
100
+ return nil , ctx .Err ()
91
101
case <- l .done :
92
102
return nil , errClosed
93
103
case l .ch <- & conn {p1 , p2 }:
You can’t perform that action at this time.
0 commit comments