Skip to content

Commit

Permalink
Move wg adds within mutex Lock (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
prettymuchbryce authored and anacrolix committed Jul 23, 2016
1 parent 78f1342 commit 59dfcf2
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions socket.go
Expand Up @@ -143,8 +143,8 @@ func (s *Socket) reader() {
defer s.destroy()
var b [maxRecvSize]byte
for {
mu.Unlock()
s.wgReadWrite.Add(1)
mu.Unlock()
n, addr, err := s.pc.ReadFrom(b[:])
s.wgReadWrite.Done()
mu.Lock()
Expand Down Expand Up @@ -543,11 +543,11 @@ func (s *Socket) WriteTo(b []byte, addr net.Addr) (n int, err error) {
if s.connDeadlines.write.passed.IsSet() {
err = errTimeout
}
s.wgReadWrite.Add(1)
defer s.wgReadWrite.Done()
mu.Unlock()
if err != nil {
return
}
s.wgReadWrite.Add(1)
defer s.wgReadWrite.Done()
return s.pc.WriteTo(b, addr)
}

0 comments on commit 59dfcf2

Please sign in to comment.