aboutsummaryrefslogtreecommitdiffstats
path: root/util/stream/zerocopy_output.cpp
blob: 23600ef6e189e527588c8282d909de8b7b875b0a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include "zerocopy_output.h"

#include <util/generic/utility.h>

void IZeroCopyOutput::DoWrite(const void* buf, size_t len) {
    void* ptr = nullptr;
    size_t writtenBytes = 0;
    while (writtenBytes < len) {
        size_t bufferSize = DoNext(&ptr);
        Y_ASSERT(ptr && bufferSize > 0);
        size_t toWrite = Min(bufferSize, len - writtenBytes);
        memcpy(ptr, static_cast<const char*>(buf) + writtenBytes, toWrite);
        writtenBytes += toWrite;
        if (toWrite < bufferSize) {
            DoUndo(bufferSize - toWrite);
        }
    }
}