示例#1
0
func blockingRead(ctx context.Context, fs *TorrentFS, t torrent.Torrent, off int64, p []byte) (n int, err error) {
	fs.mu.Lock()
	fs.blockedReads++
	fs.event.Broadcast()
	fs.mu.Unlock()
	var (
		_n   int
		_err error
	)
	readDone := make(chan struct{})
	go func() {
		r := t.NewReader()
		defer r.Close()
		_n, _err = r.ReadAt(p, off)
		close(readDone)
	}()
	select {
	case <-readDone:
		n = _n
		err = _err
	case <-fs.destroyed:
		err = fuse.EIO
	case <-ctx.Done():
		err = fuse.EINTR
	}
	fs.mu.Lock()
	fs.blockedReads--
	fs.event.Broadcast()
	fs.mu.Unlock()
	return
}
示例#2
0
func blockingRead(ctx context.Context, fs *TorrentFS, t *torrent.Torrent, off int64, p []byte) (n int, err error) {
	fs.mu.Lock()
	fs.blockedReads++
	fs.event.Broadcast()
	fs.mu.Unlock()
	var (
		_n   int
		_err error
	)
	readDone := make(chan struct{})
	go func() {
		defer close(readDone)
		r := t.NewReader()
		defer r.Close()
		_, _err = r.Seek(off, os.SEEK_SET)
		if _err != nil {
			return
		}
		_n, _err = io.ReadFull(r, p)
	}()
	select {
	case <-readDone:
		n = _n
		err = _err
	case <-fs.destroyed:
		err = fuse.EIO
	case <-ctx.Done():
		err = fuse.EINTR
	}
	fs.mu.Lock()
	fs.blockedReads--
	fs.event.Broadcast()
	fs.mu.Unlock()
	return
}
示例#3
0
func Example_fileReader() {
	var (
		t torrent.Torrent
		f torrent.File
	)
	r := t.NewReader()
	defer r.Close()
	// Access the parts of the torrent pertaining to f. Data will be
	// downloaded as required, per the configuration of the torrent.Reader.
	_ = missinggo.NewSectionReadSeeker(r, f.Offset(), f.Length())
}