MCPcopy Create free account
hub / github.com/ClassiCube/ClassiCube / Http_BufferExpand

Function Http_BufferExpand

src/_HttpBase.h:115–135  ·  view source on GitHub ↗

#######################################################################################################################* *---------------------------------------------------Common buffer code----------------------------------------------------* *#########################################################################################################################*/ Ensures data buffer has enou

Source from the content-addressed store, hash-verified

113*#########################################################################################################################*/
114/* Ensures data buffer has enough space left to append amount bytes */
115static cc_bool Http_BufferExpand(struct HttpRequest* req, cc_uint32 amount) {
116 cc_uint32 newSize = req->size + amount;
117 cc_uint8* ptr;
118 if (newSize <= req->_capacity) return true;
119
120 if (!req->_capacity) {
121 /* Allocate initial storage */
122 req->_capacity = req->contentLength ? req->contentLength : 1;
123 req->_capacity = max(req->_capacity, newSize);
124
125 ptr = (cc_uint8*)Mem_TryAlloc(req->_capacity, 1);
126 } else {
127 /* Reallocate if capacity reached */
128 req->_capacity = newSize;
129 ptr = (cc_uint8*)Mem_TryRealloc(req->data, newSize, 1);
130 }
131
132 if (!ptr) return false;
133 req->data = ptr;
134 return true;
135}
136
137/* Increases size and updates current progress */
138static void Http_BufferExpanded(struct HttpRequest* req, cc_uint32 read) {

Callers 1

HttpClient_ProcessFunction · 0.85

Calls 2

Mem_TryAllocFunction · 0.70
Mem_TryReallocFunction · 0.70

Tested by

no test coverage detected