Fix a few data races

This commit is contained in:
Matt Joiner 2015-06-03 00:00:25 +10:00
parent 9a0f830395
commit 71f5a1882a
2 changed files with 6 additions and 1 deletions

View File

@ -629,7 +629,10 @@ func (s *Server) serve() error {
logonce.Stderr.Printf("received dht packet exceeds buffer size")
continue
}
if s.ipBlocked(util.AddrIP(addr)) {
s.mu.Lock()
blocked := s.ipBlocked(util.AddrIP(addr))
s.mu.Unlock()
if blocked {
continue
}
s.processPacket(b[:n], newDHTAddr(addr))

View File

@ -35,6 +35,8 @@ type FilePieceState struct {
// Returns the state of pieces in this file.
func (f *File) State() (ret []FilePieceState) {
f.t.cl.mu.Lock()
defer f.t.cl.mu.Unlock()
pieceSize := int64(f.t.usualPieceSize())
off := f.offset % pieceSize
remaining := f.length