Pointer to request variable is NULL inside task even though it was assiged an address before task is executed.
Posted: Wed Nov 20, 2024 6:34 pm
Hello all,
I'm coding a web server that uses idf http_webserver api
In my uri handler I am saving the request pointer (httpd_req_t*) to a global variable of
the same type (httpd_req_t).
The uri handler calls a task via xTaskNotifygive() which takes as a parameter the global variable of type httpd_req_t
which has been assigned inside the uri handler.
In the task i save the passed parmeter (request ptr) to a local variable.
In the task loop I check the local request variable and it is NULL so that
my httpd_ws_send_frame(skt_req, &ws_audio_pkt) function fails.
My understanding is that as long as the global request variable is populated with a valid address
before the task is called then it should just work.
Can anyone shed some light on this ?
Thanks
Code snippets
I'm coding a web server that uses idf http_webserver api
In my uri handler I am saving the request pointer (httpd_req_t*) to a global variable of
the same type (httpd_req_t).
The uri handler calls a task via xTaskNotifygive() which takes as a parameter the global variable of type httpd_req_t
which has been assigned inside the uri handler.
In the task i save the passed parmeter (request ptr) to a local variable.
In the task loop I check the local request variable and it is NULL so that
my httpd_ws_send_frame(skt_req, &ws_audio_pkt) function fails.
My understanding is that as long as the global request variable is populated with a valid address
before the task is called then it should just work.
Can anyone shed some light on this ?
Thanks
Code snippets
Code: Select all
xTaskCreate(&read_file_task, "read_file_task", 4096, glb_req, 3, &readFileTaskHandle); //task creation
static esp_err_t socket_handler(httpd_req_t *req) //uri handler
glb_req = req; //assignment to global request variable inside handler
xTaskNotifyGive(readFileTaskHandle); //exutes the task
static void read_file_task(void *arg) //task
{
httpd_req_t *skt_req = (httpd_req_t *)arg; //assignment outside of task loop
.
.
.
ret = httpd_ws_send_frame(skt_req, &ws_audio_pkt); //inside task loop (fails since skt_req is NULL