Commit caa149f7 authored by Russ Cox's avatar Russ Cox

net: use chan bool instead of chan *netFD to avoid cycle

The cycle is *netFD -> cw chanl *netFD in struct ->
same *netFD in channel read buffer.

Because channels are finalized, the cycle makes them
uncollectable.  A better fix is to make channels not
finalized anymore, and that will happen, but this is
an easy, reasonable workaround until then.

Another good fix would be to zero the channel receive
buffer entry after the receive.  That too will happen.

R=r
CC=golang-dev
https://golang.org/cl/875043
parent 6431b984
...@@ -26,8 +26,8 @@ type netFD struct { ...@@ -26,8 +26,8 @@ type netFD struct {
family int family int
proto int proto int
sysfile *os.File sysfile *os.File
cr chan *netFD cr chan bool
cw chan *netFD cw chan bool
net string net string
laddr Addr laddr Addr
raddr Addr raddr Addr
...@@ -122,9 +122,9 @@ func (s *pollServer) AddFD(fd *netFD, mode int) { ...@@ -122,9 +122,9 @@ func (s *pollServer) AddFD(fd *netFD, mode int) {
if intfd < 0 { if intfd < 0 {
// fd closed underfoot // fd closed underfoot
if mode == 'r' { if mode == 'r' {
fd.cr <- fd fd.cr <- true
} else { } else {
fd.cw <- fd fd.cw <- true
} }
return return
} }
...@@ -166,12 +166,12 @@ func (s *pollServer) WakeFD(fd *netFD, mode int) { ...@@ -166,12 +166,12 @@ func (s *pollServer) WakeFD(fd *netFD, mode int) {
if mode == 'r' { if mode == 'r' {
for fd.ncr > 0 { for fd.ncr > 0 {
fd.ncr-- fd.ncr--
fd.cr <- fd fd.cr <- true
} }
} else { } else {
for fd.ncw > 0 { for fd.ncw > 0 {
fd.ncw-- fd.ncw--
fd.cw <- fd fd.cw <- true
} }
} }
} }
...@@ -312,8 +312,8 @@ func newFD(fd, family, proto int, net string, laddr, raddr Addr) (f *netFD, err ...@@ -312,8 +312,8 @@ func newFD(fd, family, proto int, net string, laddr, raddr Addr) (f *netFD, err
rs = raddr.String() rs = raddr.String()
} }
f.sysfile = os.NewFile(fd, net+":"+ls+"->"+rs) f.sysfile = os.NewFile(fd, net+":"+ls+"->"+rs)
f.cr = make(chan *netFD, 1) f.cr = make(chan bool, 1)
f.cw = make(chan *netFD, 1) f.cw = make(chan bool, 1)
return f, nil return f, nil
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment