how to implement Transfer complete callback in esp_idf_webserver

noweare
Posts: 79
Joined: Tue Jul 02, 2019 11:35 am

how to implement Transfer complete callback in esp_idf_webserver

Postby noweare » Sat Jun 08, 2024 12:19 am

Getting this error when trying to use "transfer complete" callback in my code:
In function 'esp_err_t echo_handler(httpd_req_t*)':
src/main.cpp:245:44: error: expression list treated as compound expression in functional cast [-fpermissive]
transfer_complete_cb(ret, socketID, msg);

in the esp_htp_sever.h there is a callback prototype

Code: Select all

typedef void (*transfer_complete_cb)(esp_err_t err, int socket, void *arg);
in my code i am calling it by:

Code: Select all

char msg[20] = "transfer complete";
 transfer_complete(ret, socketID, msg);
I am implementing the callback function like this:

Code: Select all

void transfer_complete(esp_err_t err, int socket, void *arg)
{
  char *myMsg = (char *)arg;
  log_i("transfer complete skt %d, arg %s with error %d", socket, myMsg, err);
  return;
}
I have looked at other invocations of callbacks in the example code of different componants and
sometimes the callback is registered like in events but mostly nothing special is done just drop the typedef and the * and change
the name of the function and it works but not in this case.

noweare
Posts: 79
Joined: Tue Jul 02, 2019 11:35 am

Re: how to implement Transfer complete callback in esp_idf_webserver

Postby noweare » Sat Jun 08, 2024 1:27 pm

Now the same code compiles and it works. So I don't know why that is.

But I do have a question:
What is the advantage of using that callback rather than just writing my own function?
There is no system setup to use this function as a callback in any automated way.

MicroController
Posts: 1734
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: how to implement Transfer complete callback in esp_idf_webserver

Postby MicroController » Thu Jun 13, 2024 2:59 pm

transfer_complete_cb(ret, socketID, msg);
transfer_complete_cb is the type of the callback function pointer, while your function's name is/was transfer_complete, without the _cb. So the compiler read it as you trying to cast the compound expression "ret, socketId, msg" to a value of type "transfer_complete_cb".

Who is online

Users browsing this forum: Majestic-12 [Bot] and 66 guests