| 439 | } |
| 440 | |
| 441 | function writevAll(chunks, size, pos, cb, retries = 0) { |
| 442 | this[kFs].writev(this.fd, chunks, this.pos, (er, bytesWritten, buffers) => { |
| 443 | // No data currently available and operation should be retried later. |
| 444 | if (er?.code === 'EAGAIN') { |
| 445 | er = null; |
| 446 | bytesWritten = 0; |
| 447 | } |
| 448 | |
| 449 | if (this.destroyed || er) { |
| 450 | return cb(er || new ERR_STREAM_DESTROYED('writev')); |
| 451 | } |
| 452 | |
| 453 | this.bytesWritten += bytesWritten; |
| 454 | |
| 455 | retries = bytesWritten ? 0 : retries + 1; |
| 456 | size -= bytesWritten; |
| 457 | pos += bytesWritten; |
| 458 | |
| 459 | // Try writing non-zero number of bytes up to 5 times. |
| 460 | if (retries > 5) { |
| 461 | cb(new ERR_SYSTEM_ERROR('writev failed')); |
| 462 | } else if (size) { |
| 463 | writevAll.call(this, [Buffer.concat(buffers).slice(bytesWritten)], size, pos, cb, retries); |
| 464 | } else { |
| 465 | cb(); |
| 466 | } |
| 467 | }); |
| 468 | } |
| 469 | |
| 470 | WriteStream.prototype._write = function(data, encoding, cb) { |
| 471 | this[kIsPerformingIO] = true; |