add DialContext method and use DialContext from stdlib

This commit is contained in:
Jeromy 2016-08-16 20:31:17 -07:00
parent ff394cdaae
commit e296964046
2 changed files with 6 additions and 2 deletions

View File

@ -7,7 +7,7 @@ language: go
sudo: false
go:
- 1.5.3
- 1.7
install:
- make deps

6
net.go
View File

@ -1,6 +1,7 @@
package manet
import (
"context"
"fmt"
"net"
@ -86,7 +87,10 @@ type Dialer struct {
// net.Conn, then wraps that in a Conn object (with local and
// remote Multiaddrs).
func (d *Dialer) Dial(remote ma.Multiaddr) (Conn, error) {
return d.DialContext(context.Background(), remote)
}
func (d *Dialer) DialContext(ctx context.Context, remote ma.Multiaddr) (Conn, error) {
// if a LocalAddr is specified, use it on the embedded dialer.
if d.LocalAddr != nil {
// convert our multiaddr to net.Addr friendly
@ -109,7 +113,7 @@ func (d *Dialer) Dial(remote ma.Multiaddr) (Conn, error) {
var nconn net.Conn
switch rnet {
case "tcp", "tcp4", "tcp6", "udp", "udp4", "udp6":
nconn, err = d.Dialer.Dial(rnet, rnaddr)
nconn, err = d.Dialer.DialContext(ctx, rnet, rnaddr)
if err != nil {
return nil, err
}