swarm: chunk.C maybe nil

This commit is contained in:
Delweng Zheng 2018-06-16 12:18:10 +08:00
parent 574378edb5
commit 8f03922f74
2 changed files with 6 additions and 5 deletions

View file

@ -184,8 +184,6 @@ func (self *TreeChunker) Split(data io.Reader, size int64, chunkC chan *Chunk, s
func (self *TreeChunker) split(depth int, treeSize int64, key Key, data io.Reader, size int64, jobC chan *hashJob, chunkC chan *Chunk, errC chan error, quitC chan bool, parentWg, swg, wwg *sync.WaitGroup) { func (self *TreeChunker) split(depth int, treeSize int64, key Key, data io.Reader, size int64, jobC chan *hashJob, chunkC chan *Chunk, errC chan error, quitC chan bool, parentWg, swg, wwg *sync.WaitGroup) {
//
for depth > 0 && size < treeSize { for depth > 0 && size < treeSize {
treeSize /= self.branches treeSize /= self.branches
depth-- depth--
@ -482,7 +480,6 @@ func retrieve(key Key, chunkC chan *Chunk, quitC chan bool) *Chunk {
} }
// waiting for the chunk retrieval // waiting for the chunk retrieval
select { // chunk.Size = int64(binary.LittleEndian.Uint64(chunk.SData[0:8])) select { // chunk.Size = int64(binary.LittleEndian.Uint64(chunk.SData[0:8]))
case <-quitC: case <-quitC:
// this is how we control process leakage (quitC is closed once join is finished (after timeout)) // this is how we control process leakage (quitC is closed once join is finished (after timeout))
return nil return nil

View file

@ -113,7 +113,9 @@ func (self *chunkerTester) Append(chunker Splitter, rootKey Key, data io.Reader,
// getting data // getting data
chunk.SData = stored.SData chunk.SData = stored.SData
chunk.Size = int64(binary.LittleEndian.Uint64(chunk.SData[0:8])) chunk.Size = int64(binary.LittleEndian.Uint64(chunk.SData[0:8]))
close(chunk.C) if c := chunk.C; c != nil {
close(c)
}
} }
} }
} }
@ -159,7 +161,9 @@ func (self *chunkerTester) Join(chunker Chunker, key Key, c int, chunkC chan *Ch
} }
chunk.SData = stored.SData chunk.SData = stored.SData
chunk.Size = int64(binary.LittleEndian.Uint64(chunk.SData[0:8])) chunk.Size = int64(binary.LittleEndian.Uint64(chunk.SData[0:8]))
close(chunk.C) if c := chunk.C; c != nil {
close(c)
}
i++ i++
} }
} }