[Listener] Set listerner host address
authorgichan <gichan2.jang@samsung.com>
Tue, 23 Aug 2022 04:23:38 +0000 (13:23 +0900)
committerjaeyun-jung <39614140+jaeyun-jung@users.noreply.github.com>
Tue, 23 Aug 2022 08:03:55 +0000 (17:03 +0900)
 - Set listerner host address given from user.
 - Set thread running flag before close the connection.

Signed-off-by: gichan <gichan2.jang@samsung.com>
src/libnnstreamer-edge/nnstreamer-edge-internal.c

index 98c53aea2ea9543e762f86f2e63596993a06b301..04bde8ac858cbaedbbe4344afbc3f0d97096aba0 100644 (file)
@@ -435,8 +435,10 @@ _nns_edge_close_connection (nns_edge_conn_s * conn)
 
   /* Stop and clear the message thread. */
   if (conn->msg_thread) {
-    conn->running = 0;
-    pthread_cancel (conn->msg_thread);
+    if (0 != conn->running) {
+      pthread_cancel (conn->msg_thread);
+      conn->running = 0;
+    }
     pthread_join (conn->msg_thread, NULL);
     conn->msg_thread = 0;
   }
@@ -740,6 +742,7 @@ _nns_edge_message_handler (void *thread_data)
     nns_edge_data_destroy (data_h);
     _nns_edge_cmd_clear (&cmd);
   }
+  conn->running = 0;
 
   /* Received error message from client, remove connection from table. */
   if (remove_connection) {
@@ -749,7 +752,6 @@ _nns_edge_message_handler (void *thread_data)
     g_hash_table_remove (eh->conn_table, GUINT_TO_POINTER (client_id));
   }
 
-  conn->running = 0;
   return NULL;
 }
 
@@ -944,7 +946,17 @@ _nns_edge_create_socket_listener (nns_edge_handle_s * eh)
   }
 
   saddr.sin_family = AF_INET;
-  saddr.sin_addr.s_addr = htonl (INADDR_ANY);
+
+  if ((saddr.sin_addr.s_addr = inet_addr (eh->host)) == -1) {
+    struct hostent *ent = gethostbyname (eh->host);
+    if (!ent) {
+      nns_edge_loge ("Failed to create listener, invalid host: %s.", eh->host);
+      goto error;
+    }
+
+    memmove (&saddr.sin_addr, ent->h_addr, ent->h_length);
+  }
+
   saddr.sin_port = htons (eh->port);
 
   if (bind (eh->listener_fd, (struct sockaddr *) &saddr, saddr_len) < 0 ||