[esp_http_client]: how can I tell client state?

Bryght-Richard
Posts: 103
Joined: Thu Feb 22, 2024 3:59 pm

Re: [esp_http_client]: how can I tell client state?

Postby Bryght-Richard » Mon Mar 31, 2025 6:31 pm

I was hoping to avoid a global client-state tracking variable(is_request_pending or something), but I think I can just capture the result of all calls to esp_http_client_perform() alongside the client handle. Then if lastHttpClientPerformResult == ESP_ERR_HTTP_EAGAIN, we should poll the client when we have free time. And if lastHttpClientPerformResult == ESP_ERR_HTTP_EAGAIN, we must poll the client until the currently pending response completes before sending another.

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

Re: [esp_http_client]: how can I tell client state?

Postby MicroController » Mon Mar 31, 2025 6:39 pm

Ok. I think I'm beginning to understand what you actually mean.
Setting a flag in response to HTTP_EVENT_ON_FINISH is out?

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

Re: [esp_http_client]: how can I tell client state?

Postby MicroController » Mon Mar 31, 2025 6:58 pm

Even though you don't care about the response to the "keep-alive", once you initiated the request you'll still have to keep polling to get the client ready for the next request.

You have potentially not polled through all of the previous request before getting to the keep-alive part?

Bryght-Richard
Posts: 103
Joined: Thu Feb 22, 2024 3:59 pm

Re: [esp_http_client]: how can I tell client state?

Postby Bryght-Richard » Mon Mar 31, 2025 7:51 pm

> Even though you don't care about the response to the "keep-alive", once you initiated the request you'll still have to keep polling to get the client ready for the next request.
> You have potentially not polled through all of the previous request before getting to the keep-alive part?

That's correct - for "Keep-Alive" and a few other requests I don't want to block the requesting thread until the response is ready. But then I must to finish polling the client before I can send another request. The requesting thread does have time to periodically poll the client while it is otherwise idle.

By polling the client while idle, and polling the client before sending another request, I hope to overlap the packet transmission time with other thread processing.

> Setting a flag in response to HTTP_EVENT_ON_FINISH is out?

HTTP_EVENT_ON_FINISH isn't always triggered. NGINX doesn't implement RFC2616 HTTP 408 response codes when closing a connection, so the connection just dies without an HTTP response. I should check if it triggers HTTP_EVENT_ERROR - might work to set a flag for either of them?

Bryght-Richard
Posts: 103
Joined: Thu Feb 22, 2024 3:59 pm

Re: [esp_http_client]: how can I tell client state?

Postby Bryght-Richard » Tue May 13, 2025 2:25 pm

One solution to this: wrapping all calls to the esp_http_client and saving off the return code. That return code can be used to poll or skip esp_http_client_perform() while otherwise idle to process async HTTP requests only as response data becomes available.

Who is online

Users browsing this forum: ChatGPT-User, DuckDuckGo [Bot], Google [Bot], Semrush [Bot] and 1 guest