| 31 | } |
| 32 | |
| 33 | func (this *OpenFilePool) Get() (resultFile *OpenFile, consumed bool, consumedSize int64) { |
| 34 | // 如果已经关闭,直接返回 |
| 35 | if this.isClosed { |
| 36 | return nil, false, 0 |
| 37 | } |
| 38 | |
| 39 | select { |
| 40 | case file := <-this.c: |
| 41 | if file != nil { |
| 42 | this.usedSize -= file.size |
| 43 | |
| 44 | err := file.SeekStart() |
| 45 | if err != nil { |
| 46 | _ = file.Close() |
| 47 | return nil, true, file.size |
| 48 | } |
| 49 | file.version = this.version |
| 50 | |
| 51 | return file, true, file.size |
| 52 | } |
| 53 | return nil, false, 0 |
| 54 | default: |
| 55 | return nil, false, 0 |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | func (this *OpenFilePool) Put(file *OpenFile) bool { |
| 60 | // 如果已关闭,则不接受新的文件 |