diff options
author | Russ Cox <rsc@golang.org> | 2010-04-06 16:50:27 -0700 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2010-04-06 16:50:27 -0700 |
commit | 7425b14f81f1d1e4ace3b79187533ce0b06ab636 (patch) | |
tree | 0aa1fd66b033f30a860dc09b348372cfb6f8a98c /src/pkg/net | |
parent | 5b25fc4f4479ca302d0422670bd86703c0e6e39b (diff) | |
download | golang-7425b14f81f1d1e4ace3b79187533ce0b06ab636.tar.gz |
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
http://codereview.appspot.com/875043
Diffstat (limited to 'src/pkg/net')
-rw-r--r-- | src/pkg/net/fd.go | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/pkg/net/fd.go b/src/pkg/net/fd.go index 28e85be2a..02f7319cb 100644 --- a/src/pkg/net/fd.go +++ b/src/pkg/net/fd.go @@ -26,8 +26,8 @@ type netFD struct { family int proto int sysfile *os.File - cr chan *netFD - cw chan *netFD + cr chan bool + cw chan bool net string laddr Addr raddr Addr @@ -122,9 +122,9 @@ func (s *pollServer) AddFD(fd *netFD, mode int) { if intfd < 0 { // fd closed underfoot if mode == 'r' { - fd.cr <- fd + fd.cr <- true } else { - fd.cw <- fd + fd.cw <- true } return } @@ -166,12 +166,12 @@ func (s *pollServer) WakeFD(fd *netFD, mode int) { if mode == 'r' { for fd.ncr > 0 { fd.ncr-- - fd.cr <- fd + fd.cr <- true } } else { for fd.ncw > 0 { 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 rs = raddr.String() } f.sysfile = os.NewFile(fd, net+":"+ls+"->"+rs) - f.cr = make(chan *netFD, 1) - f.cw = make(chan *netFD, 1) + f.cr = make(chan bool, 1) + f.cw = make(chan bool, 1) return f, nil } |