zerocopy_output.cpp 563 B

123456789101112131415161718
  1. #include "zerocopy_output.h"
  2. #include <util/generic/utility.h>
  3. void IZeroCopyOutput::DoWrite(const void* buf, size_t len) {
  4. void* ptr = nullptr;
  5. size_t writtenBytes = 0;
  6. while (writtenBytes < len) {
  7. size_t bufferSize = DoNext(&ptr);
  8. Y_ASSERT(ptr && bufferSize > 0);
  9. size_t toWrite = Min(bufferSize, len - writtenBytes);
  10. memcpy(ptr, static_cast<const char*>(buf) + writtenBytes, toWrite);
  11. writtenBytes += toWrite;
  12. if (toWrite < bufferSize) {
  13. DoUndo(bufferSize - toWrite);
  14. }
  15. }
  16. }