#######################################################################################################################* *---------------------------------------------------Common buffer code----------------------------------------------------* *#########################################################################################################################*/ Ensures data buffer has enou
| 113 | *#########################################################################################################################*/ |
| 114 | /* Ensures data buffer has enough space left to append amount bytes */ |
| 115 | static 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 */ |
| 138 | static void Http_BufferExpanded(struct HttpRequest* req, cc_uint32 read) { |
no test coverage detected