1 Star 0 Fork 1

lsj/go-torrent

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
dialer.go 830 Bytes
Copy Edit Raw Blame History
Matt Joiner authored 2021-06-21 13:29 . Tidy up the Dialer interface
package torrent
import (
"context"
"net"
)
// Dialers have the network locked in.
type Dialer interface {
Dial(_ context.Context, addr string) (net.Conn, error)
DialerNetwork() string
}
// An interface to ease wrapping dialers that explicitly include a network parameter.
type DialContexter interface {
DialContext(ctx context.Context, network, addr string) (net.Conn, error)
}
// Used by wrappers of standard library network types.
var DefaultNetDialer = &net.Dialer{}
// Adapts a DialContexter to the Dial interface in this package.
type NetworkDialer struct {
Network string
Dialer DialContexter
}
func (me NetworkDialer) DialerNetwork() string {
return me.Network
}
func (me NetworkDialer) Dial(ctx context.Context, addr string) (_ net.Conn, err error) {
return me.Dialer.DialContext(ctx, me.Network, addr)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/leesj/go-torrent.git
git@gitee.com:leesj/go-torrent.git
leesj
go-torrent
go-torrent
master

Search