15
15
package openssl
16
16
17
17
import (
18
+ "context"
18
19
"errors"
19
20
"net"
20
21
"time"
@@ -90,7 +91,19 @@ func Dial(network, addr string, ctx *Ctx, flags DialFlags) (*Conn, error) {
90
91
func DialTimeout (network , addr string , timeout time.Duration , ctx * Ctx ,
91
92
flags DialFlags ) (* Conn , error ) {
92
93
d := net.Dialer {Timeout : timeout }
93
- return dialSession (d , network , addr , ctx , flags , nil )
94
+ return dialSession (d , context .Background (), network , addr , ctx , flags , nil )
95
+ }
96
+
97
+ // DialContext acts like Dial but takes a context for network dial.
98
+ //
99
+ // The context includes only network dial. It does not include OpenSSL calls.
100
+ //
101
+ // See func Dial for a description of the network, addr, ctx and flags
102
+ // parameters.
103
+ func DialContext (context context.Context , network , addr string ,
104
+ ctx * Ctx , flags DialFlags ) (* Conn , error ) {
105
+ d := net.Dialer {}
106
+ return dialSession (d , context , network , addr , ctx , flags , nil )
94
107
}
95
108
96
109
// DialSession will connect to network/address and then wrap the corresponding
@@ -109,11 +122,11 @@ func DialTimeout(network, addr string, timeout time.Duration, ctx *Ctx,
109
122
func DialSession (network , addr string , ctx * Ctx , flags DialFlags ,
110
123
session []byte ) (* Conn , error ) {
111
124
var d net.Dialer
112
- return dialSession (d , network , addr , ctx , flags , session )
125
+ return dialSession (d , context . Background (), network , addr , ctx , flags , session )
113
126
}
114
127
115
- func dialSession (d net.Dialer , network , addr string , ctx * Ctx , flags DialFlags ,
116
- session []byte ) (* Conn , error ) {
128
+ func dialSession (d net.Dialer , context context. Context , network , addr string ,
129
+ ctx * Ctx , flags DialFlags , session []byte ) (* Conn , error ) {
117
130
host , _ , err := net .SplitHostPort (addr )
118
131
if err != nil {
119
132
return nil , err
@@ -127,7 +140,7 @@ func dialSession(d net.Dialer, network, addr string, ctx *Ctx, flags DialFlags,
127
140
// TODO: use operating system default certificate chain?
128
141
}
129
142
130
- c , err := d .Dial ( network , addr )
143
+ c , err := d .DialContext ( context , network , addr )
131
144
if err != nil {
132
145
return nil , err
133
146
}
0 commit comments