(file *OpenFile)
| 57 | } |
| 58 | |
| 59 | func (this *OpenFilePool) Put(file *OpenFile) bool { |
| 60 | // 如果已关闭,则不接受新的文件 |
| 61 | if this.isClosed { |
| 62 | _ = file.Close() |
| 63 | return false |
| 64 | } |
| 65 | |
| 66 | // 检查文件版本号 |
| 67 | if this.version > 0 && file.version > 0 && file.version != this.version { |
| 68 | _ = file.Close() |
| 69 | return false |
| 70 | } |
| 71 | |
| 72 | // 加入Pool |
| 73 | select { |
| 74 | case this.c <- file: |
| 75 | this.usedSize += file.size |
| 76 | return true |
| 77 | default: |
| 78 | // 多余的直接关闭 |
| 79 | _ = file.Close() |
| 80 | return false |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | func (this *OpenFilePool) Len() int { |
| 85 | return len(this.c) |