Only wait for io.Copy; Remove obsolete from client
This commit is contained in:
parent
0b529da1d9
commit
05d597a9f7
24
client.go
24
client.go
|
@ -2400,17 +2400,6 @@ func (cl *Client) allTorrentsCompleted() bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cl *Client) allNeededTorrentsCompleted() bool {
|
|
||||||
for _, t := range cl.torrents {
|
|
||||||
if !t.haveInfo() {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if ! t.neededPiecesDownloaded() {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns true when all torrents are completely downloaded and false if the
|
// Returns true when all torrents are completely downloaded and false if the
|
||||||
// client is stopped before that.
|
// client is stopped before that.
|
||||||
|
@ -2426,19 +2415,6 @@ func (me *Client) WaitAll() bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true when all requested chunks are completely downloaded and false if the
|
|
||||||
// client is stopped before that.
|
|
||||||
func (me *Client) WaitNeeded() bool {
|
|
||||||
me.mu.Lock()
|
|
||||||
defer me.mu.Unlock()
|
|
||||||
for !me.allNeededTorrentsCompleted() {
|
|
||||||
if me.stopped() {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
me.event.Wait()
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (me *Client) fillRequests(t *torrent, c *connection) {
|
func (me *Client) fillRequests(t *torrent, c *connection) {
|
||||||
if c.Interested {
|
if c.Interested {
|
||||||
|
|
|
@ -135,7 +135,7 @@ func main() {
|
||||||
}
|
}
|
||||||
dstWriter := bufio.NewWriter(f)
|
dstWriter := bufio.NewWriter(f)
|
||||||
|
|
||||||
|
done := make(chan struct{})
|
||||||
for _, arg := range posArgs {
|
for _, arg := range posArgs {
|
||||||
t := func() torrent.Torrent {
|
t := func() torrent.Torrent {
|
||||||
if strings.HasPrefix(arg, "magnet:") {
|
if strings.HasPrefix(arg, "magnet:") {
|
||||||
|
@ -171,21 +171,14 @@ func main() {
|
||||||
|
|
||||||
srcReader := io.NewSectionReader(t.NewReader(), file.Offset(), file.Length())
|
srcReader := io.NewSectionReader(t.NewReader(), file.Offset(), file.Length())
|
||||||
io.Copy(dstWriter, srcReader)
|
io.Copy(dstWriter, srcReader)
|
||||||
|
close(done)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
done := make(chan struct{})
|
|
||||||
go func() {
|
|
||||||
defer close(done)
|
|
||||||
if client.WaitNeeded() {
|
|
||||||
log.Print("downloaded ALL the torrents")
|
|
||||||
} else {
|
|
||||||
log.Fatal("y u no complete torrents?!")
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
ticker := time.NewTicker(time.Second)
|
ticker := time.NewTicker(time.Second)
|
||||||
waitDone:
|
waitDone:
|
||||||
for {
|
for {
|
||||||
|
|
|
@ -515,14 +515,6 @@ func (t *torrent) numPieces() int {
|
||||||
return t.Info.NumPieces()
|
return t.Info.NumPieces()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *torrent) neededPiecesDownloaded() bool {
|
|
||||||
for i := range iter.N(t.Info.NumPieces()) {
|
|
||||||
if t.Pieces[i].Priority != piecePriorityNone && !t.pieceComplete(i) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *torrent) numPiecesCompleted() (num int) {
|
func (t *torrent) numPiecesCompleted() (num int) {
|
||||||
for i := range iter.N(t.Info.NumPieces()) {
|
for i := range iter.N(t.Info.NumPieces()) {
|
||||||
|
|
Loading…
Reference in New Issue