Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9b590a9

Browse files
net: using runtime.AddCleanup
1 parent a8564bd commit 9b590a9

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

‎src/net/fd_posix.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type netFD struct {
2424
net string
2525
laddr Addr
2626
raddr Addr
27+
cleanup runtime.Cleanup
2728
}
2829

2930
func (fd *netFD) name() string {
@@ -40,13 +41,13 @@ func (fd *netFD) name() string {
4041
func (fd *netFD) setAddr(laddr, raddr Addr) {
4142
fd.laddr = laddr
4243
fd.raddr = raddr
43-
// TODO Replace with runtime.AddCleanup.
44-
runtime.SetFinalizer(fd, (*netFD).Close)
44+
fd.cleanup = runtime.AddCleanup(fd, func(pfd poll.FD) {
45+
_ = pfd.Close()
46+
}, fd.pfd)
4547
}
4648

4749
func (fd *netFD) Close() error {
48-
// TODO Replace with runtime.AddCleanup.
49-
runtime.SetFinalizer(fd, nil)
50+
fd.cleanup.Stop()
5051
return fd.pfd.Close()
5152
}
5253

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /