]> Kevux Git Server - kevux-tools/commitdiff
Progress: Use the f_socket_accept() in TacocaT.
authorKevin Day <kevin@kevux.org>
Sat, 5 Aug 2023 15:42:51 +0000 (10:42 -0500)
committerKevin Day <kevin@kevux.org>
Sat, 5 Aug 2023 15:42:51 +0000 (10:42 -0500)
The accept needs to be used before attempting to read from the stream.

sources/c/tacocat/main/common/print.c
sources/c/tacocat/main/common/print.h
sources/c/tacocat/main/receive.c

index 34473b9660b778681a8a2faff257bf96fd9ca6e1..1fbe0126111c9c568344b78c6334e096ed76eb3c 100644 (file)
@@ -13,6 +13,7 @@ extern "C" {
     "f_network_from_ip_name",
     "f_network_is_ip_address",
     "f_polls_increase_by",
+    "f_socket_accept",
     "f_socket_bind_inet4",
     "f_socket_bind_inet6",
     "f_socket_bind_local",
index 3f4e2dabf8d5fa029193b56ca1f2ed80329bd0be..1ddc816572d6f5f6484ee85586c09e14d367daa6 100644 (file)
@@ -46,6 +46,7 @@ extern "C" {
     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_accept_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 dc816933fe2b49003f2b30e810bdfe20e1b54088..88010f70130ce30a6567ea929b739bc77afd657c 100644 (file)
@@ -26,19 +26,29 @@ extern "C" {
           return 0;
         }
 
-        for (i = 0; i < main->setting.receive.polls.used; ++i) {
+        // Skip if status is an error or is F_time_out.
+        if (main->setting.status_receive == F_none) {
 
-          if (main->setting.receive.polls.array[i].fd == -1) continue;
+          for (i = 0; i < main->setting.receive.polls.used; ++i) {
 
-          // @todo figure out what f_poll_urgent_e can be.
-          if (main->setting.receive.polls.array[i].revents & (f_poll_read_e | f_poll_urgent_e)) {
-            kt_tacocat_receive_process(main, i);
-            if (F_status_is_error(main->setting.state.status)) continue;
-          }
-        } // for
+            if (main->setting.receive.polls.array[i].fd == -1) continue;
 
-        // @todo handle errors
-        //if (F_status_is_error(main->setting.receive.statuss.array[i])) ... // @todo more work needed to clear error bit when a new read is ready.
+            // @todo figure out what f_poll_urgent_e can be.
+            if (main->setting.receive.polls.array[i].revents & (f_poll_read_e | f_poll_urgent_e)) {
+              kt_tacocat_receive_process(main, i);
+
+              main->setting.receive.polls.array[i].revents = 0;
+
+              if (F_status_is_error(main->setting.state.status)) continue;
+            }
+          } // for
+
+          // @todo handle errors
+          //if (F_status_is_error(main->setting.receive.statuss.array[i])) ... // @todo more work needed to clear error bit when a new read is ready.
+        }
+        else {
+          // @todo handle error or F_time_out on main->setting.status_receive.
+        }
 
       } while (F_status_is_error_not(main->setting.status_receive));
     }
@@ -93,15 +103,21 @@ extern "C" {
 
     // This is a new packet (kt_tacocat_socket_flag_none_e).
     if (!(*flag)) {
+      *status = f_socket_accept(socket);
+
+      if (F_status_is_error(*status)) {
+        kt_tacocat_print_error_on(&main->program.error, macro_kt_tacocat_f(f_socket_accept), kt_tacocat_receive_s, *name, *status);
+
+        return;
+      }
+
       socket->size_read = kt_tacocat_packet_peek_d;
       *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);
 
-        if (*status == F_connect_not) {
-          // @todo errors like this (or perhaps all errors) need to ensure this function is not called again until the state is reset to prevent infinitely looping on this.
-        }
+        f_file_close_id(&socket->id_data);
 
         return;
       }
@@ -126,6 +142,9 @@ extern "C" {
 
     // f_socket_flag_peek_e,
     //f_socket_read_stream
+
+    // For now just close the socket until the appropriate code gets written here.
+    f_file_close_id(&socket->id_data);
   }
 #endif // _di_kt_tacocat_receive_process_