MCPcopy Create free account
hub / github.com/apache/brpc / appendv

Method appendv

src/butil/iobuf.cpp:1095–1119  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1093}
1094
1095int IOBuf::appendv(const const_iovec* vec, size_t n) {
1096 size_t offset = 0;
1097 for (size_t i = 0; i < n;) {
1098 IOBuf::Block* b = iobuf::share_tls_block();
1099 if (BAIDU_UNLIKELY(!b)) {
1100 return -1;
1101 }
1102 uint32_t total_cp = 0;
1103 for (; i < n; ++i, offset = 0) {
1104 const const_iovec & vec_i = vec[i];
1105 const size_t nc = std::min(vec_i.iov_len - offset, b->left_space() - total_cp);
1106 iobuf::cp(b->data + b->size + total_cp, (char*)vec_i.iov_base + offset, nc);
1107 total_cp += nc;
1108 offset += nc;
1109 if (offset != vec_i.iov_len) {
1110 break;
1111 }
1112 }
1113
1114 const IOBuf::BlockRef r = { (uint32_t)b->size, total_cp, b };
1115 b->size += total_cp;
1116 _push_back_ref(r);
1117 }
1118 return 0;
1119}
1120
1121int IOBuf::append_user_data_with_meta(void* data,
1122 size_t size,

Callers 1

TEST_FFunction · 0.45

Calls 3

share_tls_blockFunction · 0.85
cpFunction · 0.85
left_spaceMethod · 0.45

Tested by 1

TEST_FFunction · 0.36