@@ -284,6 +284,23 @@ func newUDPConn(fd *netFD) *UDPConn { return &UDPConn{conn{fd}} }
284
284
// If the IP field of raddr is nil or an unspecified IP address, the
285
285
// local system is assumed.
286
286
func DialUDP (network string , laddr , raddr * UDPAddr ) (* UDPConn , error ) {
287
+ return DialUDPContext (context .Background (), network , laddr , raddr )
288
+ }
289
+
290
+ // DialUDPContext acts like DialUDP but connects using
291
+ // the provided context.
292
+ //
293
+ // The provided Context must be non-nil.
294
+ //
295
+ // The network must be a UDP network name; see func Dial for details.
296
+ //
297
+ // If laddr is nil, a local address is automatically chosen.
298
+ // If the IP field of raddr is nil or an unspecified IP address, the
299
+ // local system is assumed.
300
+ func DialUDPContext (ctx context.Context , network string , laddr , raddr * UDPAddr ) (* UDPConn , error ) {
301
+ if ctx == nil {
302
+ panic ("nil context" )
303
+ }
287
304
switch network {
288
305
case "udp" , "udp4" , "udp6" :
289
306
default :
@@ -293,7 +310,7 @@ func DialUDP(network string, laddr, raddr *UDPAddr) (*UDPConn, error) {
293
310
return nil , & OpError {Op : "dial" , Net : network , Source : laddr .opAddr (), Addr : nil , Err : errMissingAddress }
294
311
}
295
312
sd := & sysDialer {network : network , address : raddr .String ()}
296
- c , err := sd .dialUDP (context . Background () , laddr , raddr )
313
+ c , err := sd .dialUDP (ctx , laddr , raddr )
297
314
if err != nil {
298
315
return nil , & OpError {Op : "dial" , Net : network , Source : laddr .opAddr (), Addr : raddr .opAddr (), Err : err }
299
316
}
0 commit comments