+ // Is buffer not big enough for remaining data ?
+ if (svritem->len + copyLen > svritem->bufLen)
+ {
+ // Resize buffer to accommodate enough space
+ size_t extLen = svritem->totalLen - svritem->bufLen;
+ if (extLen > COAP_TCP_MAX_BUFFER_CHUNK_SIZE)
+ {
+ extLen = COAP_TCP_MAX_BUFFER_CHUNK_SIZE;
+ }
+
+ // Allocate required memory
+ unsigned char *buffer = OICRealloc(svritem->data, svritem->bufLen + extLen);
+ if (NULL == buffer)
+ {
+ OIC_LOG(ERROR, TAG, "OICRealloc - out of memory");
+ return CA_MEMORY_ALLOC_FAILED;
+ }
+
+ svritem->data = buffer;
+ svritem->bufLen += extLen;
+ }
+
+ // Read required bytes to have full CoAP payload