MCPcopy Create free account
hub / github.com/F-Stack/f-stack / cache_append_data

Function cache_append_data

adapter/micro_thread/mt_cache.cpp:282–350  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

280}
281
282int32_t cache_append_data(TRWCache* cache, const void* data, uint32_t len)
283{
284 if ((NULL == data) || (NULL == cache) || (NULL == cache->pool))
285 {
286 return -1;
287 }
288
289 if (len == 0)
290 {
291 return 0;
292 }
293
294 uint32_t left = len;
295 uint32_t remain = 0;
296
297 TSkBuffer* tail = TAILQ_LAST(&cache->list, __sk_buff_list);
298 if (tail != NULL)
299 {
300 if (tail->end > (tail->data + tail->data_len))
301 {
302 remain = tail->end - tail->data - tail->data_len;
303 }
304
305 if (remain >= len)
306 {
307 memcpy(tail->data + tail->data_len, data, len);
308 tail->data_len += len;
309 cache->len += len;
310 return (int32_t)len;
311 }
312 }
313
314 TRWCache keep_list;
315 rw_cache_init(&keep_list, cache->pool);
316 left -= remain;
317 while (left > 0)
318 {
319 TSkBuffer* item = alloc_sk_buffer(cache->pool);
320 if (item == NULL)
321 {
322 rw_cache_destroy(&keep_list);
323 return -2;
324 }
325 cache_append_buffer(&keep_list, item);
326
327 if (left <= item->size)
328 {
329 memcpy(item->head, (char*)data + len - left, left);
330 item->data_len = left;
331 break;
332 }
333
334 memcpy(item->head, (char*)data + len - left, item->size);
335 item->data_len = item->size;
336 left -= item->size;
337 }
338
339 if ((tail != NULL) && (remain > 0))

Callers 1

cache_tcp_send_buffFunction · 0.85

Calls 5

rw_cache_initFunction · 0.85
alloc_sk_bufferFunction · 0.85
rw_cache_destroyFunction · 0.85
cache_append_bufferFunction · 0.85
memcpyFunction · 0.50

Tested by

no test coverage detected