Skip to content

Commit

Permalink
added handling of "/cluster_heartbeat/id" to the HTTP server
Browse files Browse the repository at this point in the history
  • Loading branch information
jvo203 committed Apr 18, 2024
1 parent aedef23 commit 0d3dbd6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## [5.1.8] - 2024-04-??

* added handling of _*/cluster_heartbeat/id*_ to the _*libmicrohttpd*_ HTTP server
* server-side optimisations: removed the Unix pipe and the accompanying request/response POSIX threads from three WebSocket event loop functions: <_*ws_event_loop*_>, <_*video_event_loop*_> and <_*pv_event_loop*_>

## [5.1.7] - 2024-04-09
Expand Down
27 changes: 27 additions & 0 deletions src/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ void *fetch_image(void *ptr);
void *fetch_realtime_image_spectrum(void *ptr);
void *fetch_pv_diagram(void *ptr);
int submit_progress(char *root, char *datasetid, int len, int progress);
extern void update_timestamp(void *ptr);

PGconn *jvo_db_connect(char *db);
char *get_jvo_path(PGconn *jvo_db, char *db, char *table, char *data_id);
Expand Down Expand Up @@ -1807,6 +1808,32 @@ static enum MHD_Result on_http_connection(void *cls,
return http_bad_request(connection);
}

if (strstr(url, "/cluster_heartbeat/") != NULL)
{
char *datasetId = strrchr(url, '/');

if (datasetId != NULL)
{
datasetId++; // skip the slash character

#ifdef DEBUG
printf("[C] <cluster_heartbeat> request for '%s'\n", datasetId);
#endif

void *item = get_dataset(datasetId);

if (item != NULL)
{
update_timestamp(item);
return http_ok(connection);
}
else
return http_not_found(connection);
}
else
return http_bad_request(connection);
}

if (strstr(url, "/progress/") != NULL)
{
char *datasetId = strrchr(url, '/');
Expand Down
4 changes: 2 additions & 2 deletions src/ws.c
Original file line number Diff line number Diff line change
Expand Up @@ -3870,10 +3870,10 @@ void *send_cluster_heartbeat(void *arg)

for (i = 0, iterator = cluster; iterator; iterator = iterator->next)
{
// URL: http://cluster_ip:ws_port/heartbeat/id
// URL: http://cluster_ip:ws_port/cluster_heartbeat/id
GString *url = g_string_new("http://");
g_string_append_printf(url, "%s:", (char *)iterator->data);
g_string_append_printf(url, "%" PRIu16 "/heartbeat/%.*s", options.ws_port, (int)len, datasetid);
g_string_append_printf(url, "%" PRIu16 "/cluster_heartbeat/%.*s", options.http_port, (int)len, datasetid);
// printf("[C] URL: '%s'\n", url->str);

// set the individual URL
Expand Down

0 comments on commit 0d3dbd6

Please sign in to comment.