From: Kevin Day Date: Sat, 5 Aug 2023 15:42:51 +0000 (-0500) Subject: Progress: Use the f_socket_accept() in TacocaT. X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=33886e08f1c3546858925af82900648ebd820bcf;p=kevux-tools Progress: Use the f_socket_accept() in TacocaT. The accept needs to be used before attempting to read from the stream. --- diff --git a/sources/c/tacocat/main/common/print.c b/sources/c/tacocat/main/common/print.c index 34473b9..1fbe012 100644 --- a/sources/c/tacocat/main/common/print.c +++ b/sources/c/tacocat/main/common/print.c @@ -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", diff --git a/sources/c/tacocat/main/common/print.h b/sources/c/tacocat/main/common/print.h index 3f4e2da..1ddc816 100644 --- a/sources/c/tacocat/main/common/print.h +++ b/sources/c/tacocat/main/common/print.h @@ -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, diff --git a/sources/c/tacocat/main/receive.c b/sources/c/tacocat/main/receive.c index dc81693..88010f7 100644 --- a/sources/c/tacocat/main/receive.c +++ b/sources/c/tacocat/main/receive.c @@ -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_