Skip to content

Commit

Permalink
Do not exceed IOV_MAX in ReadFile
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalif committed Nov 16, 2022
1 parent ef7d040 commit e613903
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions internal/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ type FileHandle struct {
lastReadIdx int
}

// On Linux and MacOS, IOV_MAX = 1024
const IOV_MAX = 1024
const MAX_BUF = 5 * 1024 * 1024
const READ_BUF_SIZE = 128 * 1024

Expand Down Expand Up @@ -1100,6 +1102,15 @@ func (fh *FileHandle) ReadFile(sOffset int64, sLen int64) (data [][]byte, bytesR
}
}

// Don't exceed IOV_MAX-1 for writev.
if len(data) > IOV_MAX-1 {
var tail []byte
for i := IOV_MAX-2; i < len(data); i++ {
tail = append(tail, data[i]...)
}
data = append(data[0:IOV_MAX-2], tail)
}

bytesRead = int(end-offset)

return
Expand Down

0 comments on commit e613903

Please sign in to comment.