]> Kevux Git Server - kevux-tools/commitdiff
Progress: Further work in TacocaT.
authorKevin Day <thekevinday@gmail.com>
Wed, 30 Aug 2023 02:13:42 +0000 (21:13 -0500)
committerKevin Day <thekevinday@gmail.com>
Wed, 30 Aug 2023 02:22:04 +0000 (21:22 -0500)
Get the existing, already implemented, TacocaT behavior working and without error.
This fixes some memory allocation mistakes (such as sending a memory address of a string, which the string is already the memory address that is needed).
Move the allocation logic to a separate function to make the code slightly cleaner.

For records purposes, I am currently compiling with the upcoming 0.6.7 (or a recent 0.7.0 dev release) of Featureless Make and the following command:
- `clear ; fake -U build/tacocat/ clean build -w /tmp/fll-0.7/ && ./install.sh -w /tmp/fll-0.7/`

sources/c/tacocat/main/common.c
sources/c/tacocat/main/common.h
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/receive.c
sources/c/tacocat/main/signal.c

index 30d35cb3482ef5900b640a54f576ce14cbd37053..f38a232c987484b33d14dd96b5dbbc34d1ef0aa4 100644 (file)
@@ -38,7 +38,7 @@ extern "C" {
       return;
     }
 
-   {
+    {
       f_uint16s_t choices = f_uint16s_t_initialize;
 
       // Identify and prioritize "color context" parameters.
@@ -218,13 +218,13 @@ extern "C" {
 
     f_number_unsigned_t j = 0;
     f_number_unsigned_t k = 0;
+    f_number_unsigned_t p = 0;
     f_number_unsigned_t index = 0;
     f_number_unsigned_t length = 0;
     f_status_t failed = F_okay;
     struct hostent host;
     f_network_family_ip_t family = f_network_family_ip_t_initialize;
     f_number_unsigned_t port = 0;
-    f_number_unsigned_t total = 0;
     f_string_static_t address = f_string_static_t_initialize;
 
     for (uint8_t i = 0; i < 2; ++i) {
@@ -248,53 +248,17 @@ extern "C" {
           continue;
         }
 
-        sets[i]->flags.used = 0;
-        sets[i]->names.used = 0;
-        sets[i]->buffers.used = 0;
-        sets[i]->packets.used = 0;
-        sets[i]->files.used = 0;
-        sets[i]->sockets.used = 0;
-        sets[i]->statuss.used = 0;
-        sets[i]->polls.used = 0;
+        kt_tacocat_setting_load_send_receive_allocate(main, main->program.parameters.array[parameters[i]].values.used / 2, sets[i]);
 
-        total = main->program.parameters.array[parameters[i]].values.used / 2;
+        macro_setting_load_handle_send_receive_error_continue_1(kt_tacocat_setting_load_send_receive_allocate);
 
-        main->setting.state.status = f_memory_array_increase_by(total, sizeof(uint16_t), (void **) &sets[i]->flags.array, &sets[i]->flags.used, &sets[i]->flags.size);
+        for (p = 0; p < main->program.parameters.array[parameters[i]].values.used; p += 2) {
 
-        macro_setting_load_handle_send_receive_error_continue_1(f_memory_array_increase_by);
-
-        main->setting.state.status = f_memory_array_increase_by(total, sizeof(f_string_dynamic_t), (void **) &sets[i]->names.array, &sets[i]->names.used, &sets[i]->names.size);
-
-        macro_setting_load_handle_send_receive_error_continue_1(f_memory_array_increase_by);
-
-        main->setting.state.status = f_memory_array_increase_by(total, sizeof(f_string_dynamic_t), (void **) &sets[i]->buffers.array, &sets[i]->buffers.used, &sets[i]->buffers.size);
-
-        macro_setting_load_handle_send_receive_error_continue_1(f_memory_array_increase_by);
-
-        main->setting.state.status = f_memory_array_increase_by(total, sizeof(f_fss_simple_packet_t), (void **) &sets[i]->packets.array, &sets[i]->packets.used, &sets[i]->packets.size);
-
-        macro_setting_load_handle_send_receive_error_continue_1(f_memory_array_increase_by);
-
-        main->setting.state.status = f_memory_array_increase_by(total, sizeof(f_file_t), (void **) &sets[i]->files.array, &sets[i]->files.used, &sets[i]->files.size);
-
-        macro_setting_load_handle_send_receive_error_continue_1(f_memory_array_increase_by);
-
-        main->setting.state.status = f_memory_array_increase_by(total, sizeof(f_file_t), (void **) &sets[i]->sockets.array, &sets[i]->sockets.used, &sets[i]->sockets.size);
-
-        macro_setting_load_handle_send_receive_error_continue_1(f_memory_array_increase_by);
-
-        main->setting.state.status = f_memory_array_increase_by(total, sizeof(f_status_t), (void **) &sets[i]->statuss.array, &sets[i]->statuss.used, &sets[i]->statuss.size);
-
-        macro_setting_load_handle_send_receive_error_continue_1(f_memory_array_increase_by);
-
-        main->setting.state.status = f_memory_array_increase_by(total, sizeof(f_poll_t), (void **) &sets[i]->polls.array, &sets[i]->polls.used, &sets[i]->polls.size);
-
-        macro_setting_load_handle_send_receive_error_continue_1(f_memory_array_increase_by);
+          // First parameter value represents the network address or the socket file path.
+          index = main->program.parameters.array[parameters[i]].values.array[p];
 
-        for (j = 0; j < main->program.parameters.array[parameters[i]].values.used; j += 2) {
+          j = sets[i]->statuss.used;
 
-          // First parameter value represents the network address or the socket file path.
-          index = main->program.parameters.array[parameters[i]].values.array[j];
           sets[i]->statuss.array[j] = F_okay;
           sets[i]->flags.array[j] = kt_tacocat_socket_flag_none_e;
           sets[i]->names.array[j].used = 0;
@@ -474,13 +438,14 @@ extern "C" {
               // @todo Kevux DNS resolution.
             }
 
+            ++sets[i]->buffers.used;
             ++sets[i]->files.used;
+            ++sets[i]->flags.used;
+            ++sets[i]->names.used;
+            ++sets[i]->packets.used;
             ++sets[i]->polls.used;
             ++sets[i]->sockets.used;
             ++sets[i]->statuss.used;
-            ++sets[i]->names.used;
-            ++sets[i]->buffers.used;
-            ++sets[i]->packets.used;
           }
           else {
             main->setting.state.status = F_status_set_error(F_parameter);
@@ -499,7 +464,7 @@ extern "C" {
           }
 
           // The second parameter value represents the local file to read from or write to.
-          index = main->program.parameters.array[parameters[i]].values.array[j + 1];
+          index = main->program.parameters.array[parameters[i]].values.array[p + 1];
 
           if (main->program.parameters.arguments.array[index].used) {
 
@@ -565,6 +530,62 @@ extern "C" {
   }
 #endif // _di_kt_tacocat_setting_load_send_receive_
 
+#ifndef _di_kt_tacocat_setting_load_send_receive_allocate_
+  void kt_tacocat_setting_load_send_receive_allocate(kt_tacocat_main_t * const main, const f_number_unsigned_t total, kt_tacocat_socket_set_t * const set) {
+
+    if (!main) return;
+
+    set->buffers.used = 0;
+    set->files.used = 0;
+    set->flags.used = 0;
+    set->names.used = 0;
+    set->packets.used = 0;
+    set->polls.used = 0;
+    set->sockets.used = 0;
+    set->statuss.used = 0;
+
+    if (!set) {
+      main->setting.state.status = F_status_set_error(F_parameter);
+
+      return;
+    }
+
+    main->setting.state.status = f_memory_array_increase_by(total, sizeof(f_string_dynamic_t), (void **) &set->buffers.array, &set->buffers.used, &set->buffers.size);
+
+    if (F_status_is_error_not(main->setting.state.status)) {
+      main->setting.state.status = f_memory_array_increase_by(total, sizeof(f_file_t), (void **) &set->files.array, &set->files.used, &set->files.size);
+    }
+
+    if (F_status_is_error_not(main->setting.state.status)) {
+      main->setting.state.status = f_memory_array_increase_by(total, sizeof(uint16_t), (void **) &set->flags.array, &set->flags.used, &set->flags.size);
+    }
+
+    if (F_status_is_error_not(main->setting.state.status)) {
+      main->setting.state.status = f_memory_array_increase_by(total, sizeof(f_poll_t), (void **) &set->polls.array, &set->polls.used, &set->polls.size);
+    }
+
+    if (F_status_is_error_not(main->setting.state.status)) {
+      main->setting.state.status = f_memory_array_increase_by(total, sizeof(f_string_dynamic_t), (void **) &set->names.array, &set->names.used, &set->names.size);
+    }
+
+    if (F_status_is_error_not(main->setting.state.status)) {
+      main->setting.state.status = f_memory_array_increase_by(total, sizeof(f_fss_simple_packet_range_t), (void **) &set->packets.array, &set->packets.used, &set->packets.size);
+    }
+
+    if (F_status_is_error_not(main->setting.state.status)) {
+      main->setting.state.status = f_memory_array_increase_by(total, sizeof(f_socket_t), (void **) &set->sockets.array, &set->sockets.used, &set->sockets.size);
+    }
+
+    if (F_status_is_error_not(main->setting.state.status)) {
+      main->setting.state.status = f_memory_array_increase_by(total, sizeof(f_status_t), (void **) &set->statuss.array, &set->statuss.used, &set->statuss.size);
+    }
+
+    if (F_status_is_error_not(main->setting.state.status)) {
+      main->setting.state.status = F_okay;
+    }
+  }
+#endif // _di_kt_tacocat_setting_load_send_receive_allocate_
+
 #ifndef _di_kt_tacocat_setting_load_address_port_extract_
   void kt_tacocat_setting_load_address_port_extract(kt_tacocat_main_t * const main, f_string_static_t * const address, f_number_unsigned_t * const port) {
 
@@ -628,7 +649,6 @@ extern "C" {
   }
 #endif // _di_kt_tacocat_setting_load_address_port_extract_
 
-
 #ifdef __cplusplus
 } // extern "C"
 #endif
index dc4011a1a13cd6f88f3a6c762394e71b4975c233..3eab59356ae648769ef21bb884968a58c98cab98 100644 (file)
@@ -91,6 +91,29 @@ extern "C" {
 #endif // _di_kt_tacocat_setting_load_send_receive_
 
 /**
+ * Perform the allocation for the standard program setting load process for the send and receive parameters.
+ *
+ * @param main
+ *   The main program and settings data.
+ *
+ *   This alters main.setting.state.status:
+ *     F_okay on success.
+ *
+ *     F_parameter (with error bit) if a parameter is invalid.
+ *
+ *     Errors (with error bit) from: f_memory_array_increase_by().
+ * @param total
+ *   The total arrays to allocated.
+ * @param set
+ *   The socket set to be allocated.
+ *
+ * @see f_memory_array_increase_by()
+ */
+#ifndef _di_kt_tacocat_setting_load_send_receive_allocate_
+  extern void kt_tacocat_setting_load_send_receive_allocate(kt_tacocat_main_t * const main, const f_number_unsigned_t total, kt_tacocat_socket_set_t * const set);
+#endif // _di_kt_tacocat_setting_load_send_receive_allocate_
+
+/**
  * Process the string and extract any potential port numbers.
  *
  * A port number is expected to be a digit following the last ':' at the end of the string.
index 4b06e3976236b779ba3000fdcc3cc1204100d49e..eed371706d0be0b53f97800bc88c3827f99a2a07 100644 (file)
@@ -31,6 +31,7 @@ extern "C" {
     "fll_program_parameter_process_verbosity",
     "kt_tacocat_process_socket_set_error_has",
     "kt_tacocat_setting_load_address_port_extract",
+    "kt_tacocat_setting_load_send_receive_allocate",
   };
 #endif // _di_kt_tacocat_f_a_
 
index b450f903ba1942d5a856d5b0bef07f7cbaa16e8e..2f119355e3f46238e370cbe3722d992555c4badf 100644 (file)
@@ -64,6 +64,7 @@ extern "C" {
     kt_tacocat_f_fll_program_parameter_process_verbosity_e,
     kt_tacocat_f_kt_tacocat_process_socket_set_error_has_e,
     kt_tacocat_f_kt_tacocat_setting_load_address_port_extract_e,
+    kt_tacocat_f_kt_tacocat_setting_load_send_receive_allocate_e,
   }; // enum
 #endif // _di_kt_tacocat_f_e_
 
index 1a8a3dca07f1e4f5d4954a95ced58fa7363daf45..7e55f033998f10c0b695c7d2eb131ba4f1ef7f55 100644 (file)
@@ -43,7 +43,6 @@ extern "C" {
         f_memory_array_resize(0, sizeof(f_poll_t), (void **) &sets[i]->polls.array, &sets[i]->polls.used, &sets[i]->polls.size);
         f_memory_array_resize(0, sizeof(f_socket_t), (void **) &sets[i]->sockets.array, &sets[i]->sockets.used, &sets[i]->sockets.size);
         f_memory_array_resize(0, sizeof(f_status_t), (void **) &sets[i]->statuss.array, &sets[i]->statuss.used, &sets[i]->statuss.size);
-
         f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &sets[i]->names.array, &sets[i]->names.used, &sets[i]->names.size, &f_string_dynamics_delete_callback);
         f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &sets[i]->buffers.array, &sets[i]->buffers.used, &sets[i]->buffers.size, &f_string_dynamics_delete_callback);
         f_memory_array_resize(0, sizeof(f_fss_simple_packet_range_t), (void **) &sets[i]->packets.array, &sets[i]->packets.used, &sets[i]->packets.size);
index 605d00d5de5c6479368c259ccd5933fa4d40b5c3..17a5ffc017a0dc0daefe509fc5b5b483001bf03e 100644 (file)
@@ -28,7 +28,6 @@ extern "C" {
 
         // Skip if status is an error or is F_time_out.
         if (main->setting.status_receive == F_okay) {
-
           for (i = 0; i < main->setting.receive.polls.used; ++i) {
 
             if (main->setting.receive.polls.array[i].fd == -1) continue;
@@ -69,8 +68,8 @@ extern "C" {
   void kt_tacocat_receive_process(kt_tacocat_main_t * const main, const f_number_unsigned_t index) {
 
     uint16_t * const flag = &main->setting.receive.flags.array[index];
-    f_socket_t * const socket = &main->setting.receive.sockets.array[index];
     f_poll_t * const poll = &main->setting.receive.polls.array[index];
+    f_socket_t * const socket = &main->setting.receive.sockets.array[index];
     f_status_t * const status = &main->setting.receive.statuss.array[index];
     f_string_dynamic_t * const name = &main->setting.receive.names.array[index];
     f_string_dynamic_t * const buffer = &main->setting.receive.buffers.array[index];
@@ -78,19 +77,12 @@ extern "C" {
 
     //if (poll->revents & f_poll_urgent_e) { // handle out of band, via f_socket_flag_out_of_band_e?
 
-    *status = f_memory_array_increase_by(socket->size_read, sizeof(f_char_t), (void **) &buffer->string, &buffer->used, &buffer->size);
-
-    if (F_status_is_error(*status)) {
-      kt_tacocat_print_error_on(&main->program.error, macro_kt_tacocat_f(f_memory_array_increase_by), kt_tacocat_receive_s, *name, *status);
-
-      return;
-    }
-
     size_t length = 0;
 
     // This is a new packet (kt_tacocat_socket_flag_none_e).
     if (!(*flag)) {
       buffer->used = 0;
+      socket->size_read = kt_tacocat_packet_read_d;
     }
 
     *status = f_memory_array_increase_by(socket->size_read, sizeof(f_char_t), (void **) &buffer->string, &buffer->used, &buffer->size);
@@ -111,8 +103,7 @@ extern "C" {
         return;
       }
 
-      socket->size_read = kt_tacocat_packet_peek_d;
-      *status = f_socket_read_stream(socket, f_socket_flag_peek_e, (void *) &buffer->string, &length);
+      *status = f_socket_read_stream(socket, f_socket_flag_peek_e, (void *) buffer->string, &length);
 
       if (F_status_is_error(*status)) {
         kt_tacocat_print_error_on(&main->program.error, macro_kt_tacocat_f(f_socket_read_stream), kt_tacocat_receive_s, *name, *status);
index a345ec77e9bc61a76846780570ebcfd42e550a81..6ef9a1a6f140c8256f71fc738e750e75d976fc3c 100644 (file)
@@ -7,8 +7,7 @@ extern "C" {
 #if !defined(_di_kt_tacocat_signal_check_) && defined(_di_thread_support_)
   f_status_t kt_tacocat_signal_check(kt_tacocat_main_t * const main) {
 
-    if (!main) return F_false;
-    if (main->program.signal.id == -1) return F_false;
+    if (!main || main->program.signal.id == -1) return F_false;
 
     if (!((++main->program.signal_check) % kt_tacocat_signal_check_d)) {
       if (fll_program_standard_signal_received(&main->program)) return F_true;
@@ -23,8 +22,7 @@ extern "C" {
 #if !defined(_di_kt_tacocat_signal_check_) && !defined(_di_thread_support_)
   f_status_t kt_tacocat_signal_check(kt_tacocat_main_t * const main) {
 
-    if (!main) return F_false;
-    if (main->program.signal.id == -1) return F_false;
+    if (!main || main->program.signal.id == -1) return F_false;
     if (main->program.signal_received) return F_true;
 
     return F_false;