add missing done checks in ForChild methods

This commit is contained in:
vyzo 2021-12-23 22:05:04 +02:00
parent a42700a439
commit 35f25a934f

View File

@ -394,6 +394,10 @@ func (s *ResourceScope) AddStreamForChild(incount, outcount int) error {
s.Lock()
defer s.Unlock()
if s.done {
return ErrResourceScopeClosed
}
return s.rc.addStream(incount, outcount)
}
@ -401,6 +405,10 @@ func (s *ResourceScope) RemoveStream(dir network.Direction) {
s.Lock()
defer s.Unlock()
if s.done {
return
}
var incount, outcount int
if dir == network.DirInbound {
incount = 1
@ -417,6 +425,11 @@ func (s *ResourceScope) RemoveStream(dir network.Direction) {
func (s *ResourceScope) RemoveStreamForChild(incount, outcount int) {
s.Lock()
defer s.Unlock()
if s.done {
return
}
s.rc.removeStream(incount, outcount)
}
@ -460,6 +473,10 @@ func (s *ResourceScope) AddConnForChild(incount, outcount int) error {
s.Lock()
defer s.Unlock()
if s.done {
return ErrResourceScopeClosed
}
return s.rc.addConn(incount, outcount)
}
@ -467,6 +484,10 @@ func (s *ResourceScope) RemoveConn(dir network.Direction) {
s.Lock()
defer s.Unlock()
if s.done {
return
}
var incount, outcount int
if dir == network.DirInbound {
incount = 1
@ -483,6 +504,11 @@ func (s *ResourceScope) RemoveConn(dir network.Direction) {
func (s *ResourceScope) RemoveConnForChild(incount, outcount int) {
s.Lock()
defer s.Unlock()
if s.done {
return
}
s.rc.removeConn(incount, outcount)
}
@ -490,6 +516,10 @@ func (s *ResourceScope) AddFD(count int) error {
s.Lock()
defer s.Unlock()
if s.done {
return ErrResourceScopeClosed
}
if err := s.rc.addFD(count); err != nil {
return err
}
@ -515,6 +545,11 @@ func (s *ResourceScope) AddFD(count int) error {
func (s *ResourceScope) AddFDForChild(count int) error {
s.Lock()
defer s.Unlock()
if s.done {
return ErrResourceScopeClosed
}
return s.rc.addFD(count)
}
@ -522,6 +557,10 @@ func (s *ResourceScope) RemoveFD(count int) {
s.Lock()
defer s.Unlock()
if s.done {
return
}
s.rc.removeFD(count)
for _, cst := range s.constraints {
cst.RemoveFDForChild(count)
@ -531,6 +570,11 @@ func (s *ResourceScope) RemoveFD(count int) {
func (s *ResourceScope) RemoveFDForChild(count int) {
s.Lock()
defer s.Unlock()
if s.done {
return
}
s.rc.removeFD(count)
}