41 auto localIdx = (this->idx + 1) % WIDTH;
44 auto *cbCandidate = this->cbs + localIdx;
46 if (cbCandidate->aio_fildes == -1) [[unlikely]] {
52 auto error = aio_error(cbCandidate);
53 if (error != EINPROGRESS) [[unlikely]] {
56 auto bytes = aio_return(cbCandidate);
57 assert(bytes == cbCandidate->aio_nbytes)
60 cbCandidate->aio_fildes = -1;
65 localIdx = (localIdx + 1) % WIDTH;
87 cb->aio_fildes = this->
fd;
88 cb->aio_offset = this->
offset;
90 this->max_len = std::max(this->max_len, this->offset + this->len);
92 auto postfill = (BLOCK - this->len % BLOCK) % BLOCK;
94 if (this->prefill == 0 & postfill == 0) [[likely]] {
95 cb->aio_nbytes = this->
len;
97 auto code = aio_write(cb);
100 this->offset += this->
len;
106 alignas(BLOCK)
char buf[BLOCK] = {};
108 if (this->prefill > 0) {
109 auto bytes = pread(this->fd, buf, BLOCK, this->offset);
112 memcpy((
char *) cb->aio_buf, buf, this->prefill);
116 cb->aio_nbytes = this->
len;
118 auto code = aio_write(cb);
121 this->offset += this->
len;
127 if (this->len + postfill > BLOCK | this->prefill == 0) {
129 auto bytes = pread(this->fd, buf, BLOCK, this->offset);
133 memcpy((
char *) cb->aio_buf + this->len, buf + BLOCK - postfill, postfill);
135 cb->aio_nbytes = this->len + postfill;
137 auto code = aio_write(cb);
140 this->offset += this->len + postfill - BLOCK;
141 this->prefill = BLOCK - postfill;
215 auto *data = (
char *)
ptr;
216 auto freeCap = BUFF_SIZE() - this->len;
219 auto bytesToWrite = std::min(n, freeCap);
220 memcpy(this->getBuf(), data, bytesToWrite);
222 if (this->len == BUFF_SIZE()) this->flushCbAsync();
224 data += bytesToWrite;
226 this->len += bytesToWrite;
227 freeCap = BUFF_SIZE() - this->len;