Page 1 of 1

how to implement Transfer complete callback in esp_idf_webserver

Posted: Sat Jun 08, 2024 12:19 am
by noweare
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.

Re: how to implement Transfer complete callback in esp_idf_webserver

Posted: Sat Jun 08, 2024 1:27 pm
by noweare
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.

Re: how to implement Transfer complete callback in esp_idf_webserver

Posted: Thu Jun 13, 2024 2:59 pm
by MicroController
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".