Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/net/fd_posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type netFD struct {
net string
laddr Addr
raddr Addr
cleanup runtime.Cleanup
}

func (fd *netFD) name() string {
Expand All @@ -40,13 +41,13 @@ func (fd *netFD) name() string {
func (fd *netFD) setAddr(laddr, raddr Addr) {
fd.laddr = laddr
fd.raddr = raddr
// TODO Replace with runtime.AddCleanup.
runtime.SetFinalizer(fd, (*netFD).Close)
fd.cleanup = runtime.AddCleanup(fd, func(_ int) {
_ = fd.pfd.Close()
}, 0)
}

func (fd *netFD) Close() error {
// TODO Replace with runtime.AddCleanup.
runtime.SetFinalizer(fd, nil)
fd.cleanup.Stop()
return fd.pfd.Close()
}

Expand Down