Skip to content

Commit

Permalink
[Hybrid] Reconnect to available node
Browse files Browse the repository at this point in the history
If current connection is lost, find availabe node and reconnect.
Previously, This recovery work is done by user application.
Let's make the users don't care about this work when using MQTT-HYBRID.

*edgesrc and tensor_query_* should be updated after this change.

Signed-off-by: gichan2-jang <gichan2.jang@samsung.com>
  • Loading branch information
gichan-jang committed Nov 9, 2023
1 parent cbbdd7c commit 6a5e92f
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/libnnstreamer-edge/nnstreamer-edge-internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ typedef struct
nns_edge_conn_s *conn;
} nns_edge_thread_data_s;

/**
* @brief Parse the message received from the MQTT broker and connect to the server directly.
*/
static int _mqtt_hybrid_direct_connection (nns_edge_handle_s * eh);

/**
* @brief Set socket option. nnstreamer-edge handles TCP connection now.
*/
Expand Down Expand Up @@ -777,6 +782,10 @@ _nns_edge_message_handler (void *thread_data)
_nns_edge_remove_connection (eh, client_id);
nns_edge_event_invoke_callback (eh->event_cb, eh->user_data,
NNS_EDGE_EVENT_CONNECTION_CLOSED, NULL, 0, NULL);
if (NNS_EDGE_CONNECT_TYPE_HYBRID == eh->connect_type) {
nns_edge_logd ("Connection lost! Reconnect to available node.");
ret = _mqtt_hybrid_direct_connection (eh);
}
}

return NULL;
Expand Down Expand Up @@ -1632,6 +1641,12 @@ nns_edge_connect (nns_edge_h edge_h, const char *dest_host, int dest_port)
return NNS_EDGE_ERROR_CONNECTION_FAILURE;
}

if (NNS_EDGE_ERROR_NONE == nns_edge_is_connected (eh)) {
nns_edge_logi ("NNStreamer-edge is already connected.");
nns_edge_unlock (eh);
return NNS_EDGE_ERROR_NONE;
}

SAFE_FREE (eh->dest_host);
eh->dest_host = nns_edge_strdup (dest_host);
eh->dest_port = dest_port;
Expand Down

0 comments on commit 6a5e92f

Please sign in to comment.