Return an iovec containing the same data as the buffer 'buf' with the length 'len', but split into random-sized chunks. The chunks are sized randomly between 1 and 'max_chunk_size' bytes.
| 257 | // but split into random-sized chunks. The chunks are sized randomly between 1 and |
| 258 | // 'max_chunk_size' bytes. |
| 259 | vector<struct iovec> ChunkIOVec(Random* rng, uint8_t* buf, int len, int max_chunk_size) { |
| 260 | vector<struct iovec> ret; |
| 261 | uint8_t* p = buf; |
| 262 | int rem = len; |
| 263 | while (rem > 0) { |
| 264 | int len = rng->Uniform(max_chunk_size) + 1; |
| 265 | len = std::min(len, rem); |
| 266 | ret.push_back({p, static_cast<size_t>(len)}); |
| 267 | p += len; |
| 268 | rem -= len; |
| 269 | } |
| 270 | return ret; |
| 271 | } |
| 272 | |
| 273 | // Regression test for KUDU-2218, a bug in which Writev would improperly handle |
| 274 | // partial writes in non-blocking mode. |