Open nkeonkeo opened 2 years ago
Could you give more information about the reason you want to add them and how they will be used? Thanks.
such as:
ctx, cancel := context.WithTimeout(context.Background(), 30000*time.Millisecond)
defer cancel()
taddr := &net.TCPAddr{}
c, err := net.DialTCPContext(ctx, "tcp", nil, taddr)
...
It can realize the timeout processing of DialTCP.
DialUDP and DialIP are similary like this.
Hi @nkeonkeo - Isn't that what https://pkg.go.dev/net#Dialer.DialContext does? What would your proposal allow that isn't possible as of today? Thanks!
Dialer.DialContext
will resolve the address each time, it may cause errors like:
lookup xxxx.com on 223.x.x.x:53: read udp 180.x.x.x:7792->223.x.x.x:53: i/o timeout
Use net.DialTCP
to dial net.TCPAddr
can avoid such problems.
And I hope I can use net.DialTCP
with context
to deal with timeout problems.
We could add these to net.Dialer, which is what we are using instead of adding new context-aware versions of all the top-level functions. The specific methods we'd need to add would be:
DialTCP(context.Context, string, *TCPAddr, *TCPAddr) (*TCPConn, error)
DialUDP
DialIP
DialUnix
Note that all take contexts but don't say "Context" in the name.
Thoughts?
This proposal has been added to the active column of the proposals project and will now be reviewed at the weekly proposal review meetings. — rsc for the proposal review group
Any objections to https://github.com/golang/go/issues/49097#issuecomment-953157835 ?
With the introduction of net/netip, we should probably make these new methods use those types (netip.AddrPort) instead of TCPAddr, UDPAddr.
It sounds like we should be adding these methods on net.Dialer:
DialTCP(context.Context, string, netip.AddrPort, netip.AddrPort) (*TCPConn, error)
DialUDP(context.Context, string, netip.AddrPort, netip.AddrPort) (*TCPConn, error)
DialIP(context.Context, string, netip.Addr, netip.Addr) (*TCPConn, error)
DialUnix(context.Context, string, *UnixAddr, *UnixAddr) (*UnixConn, error)
Does anyone object to these?
Based on the discussion above, this proposal seems like a likely accept. — rsc for the proposal review group
No change in consensus, so accepted. 🎉 This issue now tracks the work of implementing the proposal. — rsc for the proposal review group
Change https://golang.org/cl/377155 mentions this issue: net: add DialUDPContext version of DialUDP
Change https://go.dev/cl/490975 mentions this issue: net: context aware network Dialer.Dial functions
Where is this proposal at? Its been accepted, but https://github.com/golang/go/pull/50534 has been closed.
The accepted proposal is to add new methods to
new.Dialer
: https://github.com/golang/go/issues/49097#issuecomment-989057178--
Such like given below: