]> Kevux Git Server - kevux-tools/commitdiff
Progress: Further work in TacocaT.
authorKevin Day <kevin@kevux.org>
Tue, 11 Jul 2023 03:04:58 +0000 (22:04 -0500)
committerKevin Day <kevin@kevux.org>
Tue, 11 Jul 2023 03:04:58 +0000 (22:04 -0500)
Get listen working.
Setup poll handler.

sources/c/tacocat/main/common.c
sources/c/tacocat/main/common/print.c
sources/c/tacocat/main/common/print.h
sources/c/tacocat/main/common/type.c
sources/c/tacocat/main/common/type.h
sources/c/tacocat/main/process.c

index ff6eaca206505cb6093feaddc39c4c221dc2090e..074994b67db599f90355e51ce3c7000abebbcd18 100644 (file)
@@ -208,6 +208,7 @@ extern "C" {
 
         sets[i]->names.used = 0;
         sets[i]->buffers.used = 0;
+        sets[i]->polls.used = 0;
 
         main->setting.state.status = f_string_dynamics_increase_by(main->program.parameters.array[parameters[i]].values.used / 2, &sets[i]->names);
 
@@ -229,6 +230,10 @@ extern "C" {
 
         macro_setting_load_handle_send_receive_error_continue_1(f_statuss_increase_by);
 
+        main->setting.state.status = f_polls_increase_by(main->program.parameters.array[parameters[i]].values.used / 2, &sets[i]->polls);
+
+        macro_setting_load_handle_send_receive_error_continue_1(f_polls_increase_by);
+
         for (j = 0; j < main->program.parameters.array[parameters[i]].values.used; j += 2) {
 
           // First parameter value represents the network address or the socket file path.
@@ -261,7 +266,7 @@ extern "C" {
               sets[i]->names.array[j].string[sets[i]->names.array[j].used] = 0;
               sets[i]->sockets.array[j].domain = f_socket_protocol_family_local_e;
               sets[i]->sockets.array[j].protocol = f_socket_protocol_tcp_e;
-              sets[i]->sockets.array[j].type = f_socket_address_family_local_e;
+              sets[i]->sockets.array[j].type = f_socket_type_stream_e;
               sets[i]->sockets.array[j].name = sets[i]->names.array[j];
             }
             else if (main->setting.flag & kt_tacocat_main_flag_resolve_classic_e) {
@@ -388,7 +393,7 @@ extern "C" {
               }
 
               sets[i]->sockets.array[j].protocol = f_socket_protocol_tcp_e;
-              sets[i]->sockets.array[j].type = host.h_addrtype;
+              sets[i]->sockets.array[j].type = f_socket_type_stream_e;
 
               if (host.h_addrtype == f_socket_address_family_inet4_e) {
                 sets[i]->sockets.array[j].domain = f_socket_protocol_family_inet4_e;
@@ -406,6 +411,7 @@ extern "C" {
             }
 
             ++sets[i]->files.used;
+            ++sets[i]->polls.used;
             ++sets[i]->sockets.used;
             ++sets[i]->statuss.used;
             ++sets[i]->names.used;
index 7b44ec869c2c9a71f54088d9084fa8d656418da1..ff8f56b8ed724e51fe1840bbfa992bed8d704771 100644 (file)
@@ -11,6 +11,7 @@ extern "C" {
     "f_files_increase_by",
     "f_network_from_ip_name",
     "f_network_is_ip_address",
+    "f_polls_increase_by",
     "f_socket_bind_inet4",
     "f_socket_bind_inet6",
     "f_socket_bind_local",
index 75dc03e06dc8fe6daca41cc0c8c51beec7f1246a..d8dfe2d4747752a7fca623dbf535831ef4a60733 100644 (file)
@@ -44,6 +44,7 @@ extern "C" {
     kt_tacocat_f_f_files_increase_by_e,
     kt_tacocat_f_f_network_from_ip_name_e,
     kt_tacocat_f_f_network_is_ip_address_e,
+    kt_tacocat_f_f_polls_increase_by_e,
     kt_tacocat_f_f_socket_bind_inet4_e,
     kt_tacocat_f_f_socket_bind_inet6_e,
     kt_tacocat_f_f_socket_bind_local_e,
index bd51e72b2494b6c13ed6204546a348df1a1f5d01..9afdfc2f5ef7e2f6ebd1372f85c99ec59455e302 100644 (file)
@@ -38,6 +38,7 @@ extern "C" {
         } // for
 
         f_files_resize(0, &sets[i]->files);
+        f_polls_resize(0, &sets[i]->polls);
         f_sockets_resize(0, &sets[i]->sockets);
         f_statuss_resize(0, &sets[i]->statuss);
 
index 7a8c116a2e57e55c7f27396b3c96929fa6ff22d8..1ca5726a9908e0c6d3fffd86a2ab286c88628f3a 100644 (file)
@@ -22,8 +22,10 @@ extern "C" {
  * block_size: The size in bytes to used to represent a block when sending or receiving packets.
  *
  * files:   An array of files for each socket.
+ * polls:  An array of sockets to poll, specifically for passing to f_file_poll().
  * sockets: An array of the network sockets.
  * statuss: An array of statuses for each socket.
+ *
  * names:   An array of names for each socket.
  * buffers: An array of buffers for sending or receiving data between clients for each socket.
  */
@@ -32,8 +34,10 @@ extern "C" {
     f_number_unsigned_t block_size;
 
     f_files_t files;
+    f_polls_t polls;
     f_sockets_t sockets;
     f_statuss_t statuss;
+
     f_string_dynamics_t names;
     f_string_dynamics_t buffers;
   } kt_tacocat_socket_set_t;
@@ -42,6 +46,7 @@ extern "C" {
     { \
       kt_tacocat_block_size_d, \
       f_files_t_initialize, \
+      f_polls_t_initialize, \
       f_sockets_t_initialize, \
       f_statuss_t_initialize, \
       f_string_dynamics_t_initialize, \
@@ -52,6 +57,7 @@ extern "C" {
     { \
       block_size, \
       f_files_t_initialize, \
+      f_polls_t_initialize, \
       f_sockets_t_initialize, \
       f_statuss_t_initialize, \
       f_string_dynamics_t_initialize, \
@@ -73,7 +79,7 @@ extern "C" {
  * receive: The socket set for receiving data receive clients.
  * send:    The socket set for sending data send clients.
  *
- * buffer:   A string buffer used for caching purposes.
+ * buffer: A string buffer used for caching purposes.
  */
 #ifndef _di_kt_tacocat_setting_t_
   typedef struct {
index 0fbe9a3c347d0ad1dcb7f4f186473a1c201c3294..c7f71d909a0ba4d9161924442bd172ffe0b4ebc1 100644 (file)
@@ -176,9 +176,25 @@ extern "C" {
 
         continue;
       }
+
+      if (main->setting.receive.sockets.array[i].id == -1) {
+        main->setting.receive.polls.array[i].fd = -1;
+        main->setting.receive.polls.array[i].events = 0;
+        main->setting.receive.polls.array[i].revents = 0;
+      }
+      else {
+        main->setting.receive.polls.array[i].fd = main->setting.receive.sockets.array[i].id;
+        main->setting.receive.polls.array[i].events = f_poll_read_e | f_poll_urgent_e;
+        main->setting.receive.polls.array[i].revents = 0;
+      }
     } // for
 
     if (F_status_is_error_not(main->setting.state.status)) {
+      // @todo this is where another process should poll/wait for connections and such (in another thread/fork).
+      main->setting.state.status = f_file_poll(main->setting.receive.polls, 9000); // @todo temporarily set to 9 second(s).
+
+      // @todo handle errors, but this will be in a fork/thread.
+
       main->setting.state.status = F_none;
     }
   }