Skip to content
9 changes: 9 additions & 0 deletions modules/rest_client/rest_cb.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,12 @@ size_t header_func(char *ptr, size_t size, size_t nmemb, void *userdata)
return len;
}

int timer_cb(CURLM *multi_handle, long timeout_ms, void *cbp)
{
LM_DBG("multi_handle timer called %ld\n", timeout_ms);
long *p = (long*) cbp;

*p = timeout_ms;

return 0;
Copy link
Collaborator

@bcnewlin bcnewlin Sep 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feedback from ChatGPT:

timer_cb writes timeout_ms into a variable, but the multi-socket path requires you to arm/cancel a real timer when the callback is called:
	•	timeout_ms == -1 → delete timer
	•	timeout_ms == 0 → call curl_multi_socket_action(..., CURL_SOCKET_TIMEOUT, 0) ASAP
Make sure the surrounding code actually honors those semantics; the callback alone is not enough. (This is from libcurl docs

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a simple timer that gets decremented on each call of multi_socket_action and I just have a static variable in the source to track it, if we wanted this to run multiple concurrent requests or attach running handles we'd need to re evaluate that and create some extra context but for now it works fine and it times out when the curl timeout that is configured times out

}
3 changes: 3 additions & 0 deletions modules/rest_client/rest_cb.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#ifndef _REST_CB_H_
#define _REST_CB_H_

#include <curl/curl.h>

#include "rest_client.h"

#include "../../str.h"
Expand All @@ -41,6 +43,7 @@

size_t write_func(char *ptr, size_t size, size_t nmemb, void *userdata);
size_t header_func(char *ptr, size_t size, size_t nmemb, void *userdata);
int timer_cb(CURLM *multi_handle, long timeout_ms, void *cbp);

#endif /* _REST_CB_H_ */

Loading
Loading