This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Managing big responses with HTTPs GET

Hi,

I have developed succesfully an HTTPs client but I am facing a problem related to a relatively long response from the server when I issue a GET request. After the GET request, when I try to receive the response I usually receive it in two chunks: headers and body. One of my GET requests returns a body of approximately 12kB and when this happens, my receive function only returns the bytes that correspond to the header. It does not show any apparent error, from my device's point of view the transmission ended after the header (which ironically include the content length of the body: 12kB).

By checking the forums I understood from various posts that:

  1. The socket reception buffer size is 4096 and cannot be increased.
  2. The SO_RCVBUF option for set/getsockopt is not available.
  3. The data received at the socket is accumulated in a buffer that reallocates for memory needs.
  4. I assume that when the data is accumulated, it is using heap memory.

My hypothesis was that 12kB was too big for my heap so I tried to increase it. For that I used this function, which checked the amount of available heap:

void memcheck(void){
	// perform free memory check
	int blockSize = 16;
	int i = 1;
	printk("Checking memory with blocksize %d char ...\n", blockSize);
	while (true) {
		char *p = (char *) malloc(i * blockSize);
		if (p == NULL){
			break;
		}
		free(p);
		++i;
	}
	printk("Ok for %d char\n", (i - 1) * blockSize);
}

And I saw that the returned value increased when I reduced the value of CONFIG_HEAP_MEM_POOL_SIZE. Which makes me wonder if I understand how it works: Does it fix the minimal amount of memory allocated for each k_malloc call?

Eventhough the function returned that I had 90kB of heap available, the reception of the GET request was not working successfully.

I have run out of ideas, do you have any idea why this may be happening?

Thanks,

Aleix.

EDIT: I forgot to mention I am using NB-IoT just in case you need to know.

Parents Reply Children
Related