RemoveNextInRange removes the next FD that falls within the given range, and returns the FD number and FileDescription of the removed FD. N.B. Callers are required to use DecRef on the returned file when they are done.
(ctx context.Context, startFd int32, endFd int32)
| 512 | // |
| 513 | // N.B. Callers are required to use DecRef on the returned file when they are done. |
| 514 | func (f *FDTable) RemoveNextInRange(ctx context.Context, startFd int32, endFd int32) (int32, *vfs.FileDescription) { |
| 515 | if startFd < 0 || startFd > endFd { |
| 516 | return MaxFdLimit, nil |
| 517 | } |
| 518 | |
| 519 | f.mu.Lock() |
| 520 | fdUint, err := f.fdBitmap.FirstOne(uint32(startFd)) |
| 521 | fd := int32(fdUint) |
| 522 | if err != nil || fd > endFd { |
| 523 | f.mu.Unlock() |
| 524 | return MaxFdLimit, nil |
| 525 | } |
| 526 | df := f.set(fd, nil, FDFlags{}) // Zap entry. |
| 527 | if df != nil { |
| 528 | f.fdBitmap.Remove(uint32(fd)) |
| 529 | } |
| 530 | f.mu.Unlock() |
| 531 | |
| 532 | if df != nil { |
| 533 | f.fileUnlock(ctx, df) |
| 534 | // Table's reference on df is transferred to caller, so don't DecRef. |
| 535 | } |
| 536 | return fd, df |
| 537 | } |
| 538 | |
| 539 | // GetLastFd returns the last set FD in the FDTable bitmap. |
| 540 | func (f *FDTable) GetLastFd() int32 { |
no test coverage detected