From 483397725c7e9eac50c6812740a1f59adbe60aba Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Fri, 8 Dec 2023 21:58:16 -0600 Subject: [PATCH] Progress: Further work in TacocaT. Get the current state of the project in sync with the recent f_socket_connect() changes. Currently, the send is failing on f_socket_write_stream() due to code 414 (F_pipe). This is the next point of investigation. --- sources/c/tacocat/main/common.c | 4 +++ sources/c/tacocat/main/common/print.c | 4 +-- sources/c/tacocat/main/common/print.h | 4 +-- sources/c/tacocat/main/print/error.c | 44 ++++++++++++++--------------- sources/c/tacocat/main/print/error.h | 52 ++++++++++++++++------------------- sources/c/tacocat/main/process.c | 20 +++----------- sources/c/tacocat/main/receive.c | 48 ++++++++++++++++---------------- sources/c/tacocat/main/send.c | 16 ++++++++--- 8 files changed, 89 insertions(+), 103 deletions(-) diff --git a/sources/c/tacocat/main/common.c b/sources/c/tacocat/main/common.c index 333827a..3cfbc50 100644 --- a/sources/c/tacocat/main/common.c +++ b/sources/c/tacocat/main/common.c @@ -348,6 +348,7 @@ extern "C" { sets[i]->array[j].status = F_okay; sets[i]->array[j].socket.id = -1; sets[i]->array[j].socket.id_data = -1; + sets[i]->array[j].socket.form = f_socket_address_form_generic_e; sets[i]->array[j].write_state.conversion = f_conversion_data_base_10_c; sets[i]->array[j].write_state.cache = &sets[i]->array[j].cache; @@ -398,14 +399,17 @@ extern "C" { if (main->setting.state.status == F_network_version_four) { host.h_addrtype = f_socket_address_family_inet4_e; family.type = f_network_family_ip_4_e; + sets[i]->array[j].socket.form = f_socket_address_form_inet4_e; } else if (main->setting.state.status == F_network_version_six) { host.h_addrtype = f_socket_address_family_inet6_e; family.type = f_network_family_ip_6_e; + sets[i]->array[j].socket.form = f_socket_address_form_inet6_e; } else { host.h_addrtype = 0; family.type = f_network_family_none_e; + sets[i]->array[j].socket.form = f_socket_address_form_generic_e; } kt_tacocat_setting_load_address_port_extract(main, range_ip, &address, &port); diff --git a/sources/c/tacocat/main/common/print.c b/sources/c/tacocat/main/common/print.c index 3763f8c..f19dea3 100644 --- a/sources/c/tacocat/main/common/print.c +++ b/sources/c/tacocat/main/common/print.c @@ -20,9 +20,7 @@ extern "C" { "f_network_from_ip_string", "f_network_is_ip_address", "f_socket_accept", - "f_socket_bind_inet4", - "f_socket_bind_inet6", - "f_socket_bind_local", + "f_socket_bind", "f_socket_close", "f_socket_connect", "f_socket_create", diff --git a/sources/c/tacocat/main/common/print.h b/sources/c/tacocat/main/common/print.h index 58e05e2..03d35bb 100644 --- a/sources/c/tacocat/main/common/print.h +++ b/sources/c/tacocat/main/common/print.h @@ -53,9 +53,7 @@ extern "C" { kt_tacocat_f_f_network_from_ip_string_e, kt_tacocat_f_f_network_is_ip_address_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, + kt_tacocat_f_f_socket_bind_e, kt_tacocat_f_f_socket_close_e, kt_tacocat_f_f_socket_connect_e, kt_tacocat_f_f_socket_create_e, diff --git a/sources/c/tacocat/main/print/error.c b/sources/c/tacocat/main/print/error.c index 6c86946..6f2f538 100644 --- a/sources/c/tacocat/main/print/error.c +++ b/sources/c/tacocat/main/print/error.c @@ -64,30 +64,6 @@ extern "C" { } #endif // _di_kt_tacocat_print_error_ -#ifndef _di_kt_tacocat_print_error_on_buffer_too_large_ - f_status_t kt_tacocat_print_error_on_buffer_too_large(fl_print_t * const print, const f_string_static_t on, const f_string_static_t network, const f_number_unsigned_t size_expect, const f_number_unsigned_t size_got) { - - if (!print) return F_status_set_error(F_output_not); - if (print->verbosity < f_console_verbosity_error_e) return F_output_not; - - f_file_stream_lock(print->to); - - fl_print_format("%[%QNetwork packet is too large for%] ", print->to, print->set->error, print->prefix, print->set->error); - fl_print_format(f_string_format_Q_single_s.string, print->to, print->set->notable, on, print->set->notable); - fl_print_format(" %[buffer for '%]", print->to, print->set->error, print->set->error, f_string_eol_s); - fl_print_format(f_string_format_Q_single_s.string, print->to, print->set->notable, network, print->set->notable); - fl_print_format("%[', the maximum size is%] ", print->to, print->set->error, print->set->error); - fl_print_format("%[%ul%]", print->to, print->set->notable, size_expect, print->set->notable); - fl_print_format("%[, and the provided size is%] ", print->to, print->set->error, print->set->error); - fl_print_format("%[%ul%]", print->to, print->set->notable, size_got, print->set->notable); - fl_print_format(f_string_format_sentence_end_s.string, print->to, print->set->error, print->set->error, f_string_eol_s); - - f_file_stream_unlock(print->to); - - return F_okay; - } -#endif // _di_kt_tacocat_print_error_on_buffer_too_large_ - #ifndef _di_kt_tacocat_print_error_on_file_too_large_ f_status_t kt_tacocat_print_error_on_file_too_large(fl_print_t * const print, f_string_static_t file, const f_string_static_t on, const f_string_static_t network, const f_number_unsigned_t size_expect, const f_number_unsigned_t size_got) { @@ -178,6 +154,26 @@ extern "C" { } #endif // _di_kt_tacocat_print_error_on_file_send_ +#ifndef _di_kt_tacocat_print_error_on_packet_invalid_ + f_status_t kt_tacocat_print_error_on_packet_invalid(fl_print_t * const print, const f_string_static_t on, const f_string_static_t network) { + + if (!print) return F_status_set_error(F_output_not); + if (print->verbosity < f_console_verbosity_error_e) return F_output_not; + + f_file_stream_lock(print->to); + + fl_print_format("%[%QNetwork packet is invalid for%] ", print->to, print->set->error, print->prefix, print->set->error); + fl_print_format(f_string_format_Q_single_s.string, print->to, print->set->notable, on, print->set->notable); + fl_print_format(" %[buffer for '%]", print->to, print->set->error, print->set->error, f_string_eol_s); + fl_print_format(f_string_format_Q_single_s.string, print->to, print->set->notable, network, print->set->notable); + fl_print_format("%['.%]%r", print->to, print->set->error, print->set->error, f_string_eol_s); + + f_file_stream_unlock(print->to); + + return F_okay; + } +#endif // _di_kt_tacocat_print_error_on_packet_invalid_ + #ifndef _di_kt_tacocat_print_error_on_max_retries_ f_status_t kt_tacocat_print_error_on_max_retries(fl_print_t * const print, const f_string_static_t on, const f_string_static_t network, const f_string_static_t name) { diff --git a/sources/c/tacocat/main/print/error.h b/sources/c/tacocat/main/print/error.h index a864cfa..0a3fc5c 100644 --- a/sources/c/tacocat/main/print/error.h +++ b/sources/c/tacocat/main/print/error.h @@ -125,34 +125,6 @@ extern "C" { #endif // _di_kt_tacocat_print_error_on_ /** - * Print network-related error message for when buffer is too large to accept additional packet blocks. - * - * @param print - * The output structure to print to. - * - * This does not alter print.custom.setting.state.status. - * @param on - * The network connection direction, which should either be "receive" or "send". - * @param network - * The name of the network in which the error is related. - * @param size_max - * The maximum buffer size. - * @param size_got - * The provided buffer size. - * - * @return - * F_okay on success. - * F_output_not on success, but no printing is performed. - * - * F_output_not (with error bit) if setting is NULL. - * - * @see fll_error_file_print() - */ -#ifndef _di_kt_tacocat_print_error_on_buffer_too_large_ - extern f_status_t kt_tacocat_print_error_on_buffer_too_large(fl_print_t * const print, const f_string_static_t on, const f_string_static_t network, const f_number_unsigned_t size_expect, const f_number_unsigned_t size_got); -#endif // _di_kt_tacocat_print_error_on_buffer_too_large_ - -/** * Print network-related error message for when file is too large to send. * * @param print @@ -273,6 +245,30 @@ extern "C" { #endif // _di_kt_tacocat_print_error_on_file_send_ /** + * Print network-related error message for when a packet is invalid. + * + * @param print + * The output structure to print to. + * + * This does not alter print.custom.setting.state.status. + * @param on + * The network connection direction, which should either be "receive" or "send". + * @param network + * The name of the network in which the error is related. + * + * @return + * F_okay on success. + * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + * + * @see fll_error_file_print() + */ +#ifndef _di_kt_tacocat_print_error_on_packet_invalid_ + extern f_status_t kt_tacocat_print_error_on_packet_invalid(fl_print_t * const print, const f_string_static_t on, const f_string_static_t network); +#endif // _di_kt_tacocat_print_error_on_packet_invalid_ + +/** * Print error message regarding maximum retries after error reached. * * This could be on any error, such as errors on file load, memory, access, or network failures. diff --git a/sources/c/tacocat/main/process.c b/sources/c/tacocat/main/process.c index f8a3419..49945a3 100644 --- a/sources/c/tacocat/main/process.c +++ b/sources/c/tacocat/main/process.c @@ -120,14 +120,8 @@ extern "C" { for (main->setting.receive.array[i].retry = 0; main->setting.receive.array[i].retry < kt_tacocat_startup_retry_max_d; ++main->setting.receive.array[i].retry) { - if (main->setting.receive.array[i].socket.domain == f_socket_protocol_family_inet4_e) { - main->setting.receive.array[i].status = f_socket_bind_inet4(&main->setting.receive.array[i].socket); - } - else if (main->setting.receive.array[i].socket.domain == f_socket_protocol_family_inet6_e) { - main->setting.receive.array[i].status = f_socket_bind_inet6(&main->setting.receive.array[i].socket); - } - else if (main->setting.receive.array[i].socket.domain == f_socket_protocol_family_local_e) { - main->setting.receive.array[i].status = f_socket_bind_local(&main->setting.receive.array[i].socket); + if (main->setting.receive.array[i].socket.form == f_socket_address_form_inet4_e || main->setting.receive.array[i].socket.form == f_socket_address_form_inet6_e || main->setting.receive.array[i].socket.form == f_socket_address_form_local_e) { + main->setting.receive.array[i].status = f_socket_bind(&main->setting.receive.array[i].socket); } else { main->setting.status_receive = F_status_set_error(F_parameter); @@ -177,13 +171,7 @@ extern "C" { kt_tacocat_print_error_on_busy(&main->program.error, kt_tacocat_receive_s, main->setting.receive.array[i].network); } else { - kt_tacocat_print_error_status(&main->program.error, main->setting.receive.array[i].socket.domain == f_socket_protocol_family_inet4_e - ? macro_kt_tacocat_f(f_socket_bind_inet4) - : main->setting.receive.array[i].socket.domain == f_socket_protocol_family_inet6_e - ? macro_kt_tacocat_f(f_socket_bind_inet6) - : macro_kt_tacocat_f(f_socket_bind_local), - main->setting.status_receive - ); + kt_tacocat_print_error_status(&main->program.error, macro_kt_tacocat_f(f_socket_bind), main->setting.status_receive); } continue; @@ -257,7 +245,7 @@ extern "C" { for (main->setting.send.array[i].retry = 0; main->setting.send.array[i].retry < kt_tacocat_startup_retry_max_d; ++main->setting.send.array[i].retry) { if (main->setting.send.array[i].socket.domain == f_socket_protocol_family_inet4_e || main->setting.send.array[i].socket.domain == f_socket_protocol_family_inet6_e || main->setting.send.array[i].socket.domain == f_socket_protocol_family_local_e) { - main->setting.send.array[i].status = f_socket_connect(main->setting.send.array[i].socket); // @fixme this is currently failing because part of the parameters is invalid (figure out why). + main->setting.send.array[i].status = f_socket_connect(&main->setting.send.array[i].socket); // The id_data socket ID is the same when sending (writing) to the socket. if (F_status_is_error_not(main->setting.send.array[i].status)) { diff --git a/sources/c/tacocat/main/receive.c b/sources/c/tacocat/main/receive.c index ea44280..e091e48 100644 --- a/sources/c/tacocat/main/receive.c +++ b/sources/c/tacocat/main/receive.c @@ -196,9 +196,11 @@ extern "C" { kt_tacocat_print_error_on_packet_too_small(&main->program.error, kt_tacocat_receive_s, set->network, kt_tacocat_packet_peek_d, set->buffer.used); set->buffer.used = 0; + set->flag = 0; + set->packet.control = 0; + set->packet.size = 0; set->retry = 0; set->status = F_status_set_error(F_packet_too_small); - set->flag = 0; return; } @@ -212,6 +214,7 @@ extern "C" { set->flag = 0; set->packet.control = 0; set->packet.size = 0; + set->retry = 0; set->status = F_status_set_error(F_packet_too_small); return; @@ -225,38 +228,33 @@ extern "C" { set->status = f_fss_simple_packet_extract_range(set->buffer, &set->packet); macro_kt_receive_process_begin_handle_error_exit_1(main, f_fss_simple_packet_extract_range, set->network, set->status, set->name, set->flag); - if (set->status == F_packet_too_small || set->packet.size < kt_tacocat_packet_minimum_d) { - kt_tacocat_print_error_on_packet_too_small(&main->program.error, kt_tacocat_receive_s, set->network, kt_tacocat_packet_peek_d, set->buffer.used); - + if (set->status == F_packet_too_small || set->packet.size < kt_tacocat_packet_minimum_d || set->packet.size > main->setting.max_buffer) { set->buffer.used = 0; - set->flag = 0; - set->packet.control = 0; - set->packet.size = 0; - set->status = F_status_set_error(F_packet_too_small); - return; - } - - if (main->setting.flag & kt_tacocat_main_flag_max_buffer_e) { - if (set->packet.size > main->setting.max_buffer) { - set->buffer.used = 0; + if (set->buffer.size > kt_tacocat_max_maintain_d) { + set->status = f_memory_array_resize(kt_tacocat_max_maintain_d, sizeof(f_char_t), (void **) &set->buffer.string, &set->buffer.used, &set->buffer.size); - if (set->buffer.size > kt_tacocat_max_maintain_d) { - set->status = f_memory_array_resize(kt_tacocat_max_maintain_d, sizeof(f_char_t), (void **) &set->buffer.string, &set->buffer.used, &set->buffer.size); - - // Report the resize error but do not fail. - if (F_status_is_error(set->status)) { - kt_tacocat_print_error_on(&main->program.error, macro_kt_tacocat_f(f_memory_array_resize), kt_tacocat_receive_s, set->network, set->status, set->name); - } + // Report the resize error but do not fail. + if (F_status_is_error(set->status)) { + kt_tacocat_print_error_on(&main->program.error, macro_kt_tacocat_f(f_memory_array_resize), kt_tacocat_receive_s, set->network, set->status, set->name); } + } + set->flag = 0; + set->packet.control = 0; + set->packet.size = 0; + set->retry = 0; + + if (set->status == F_packet_too_small || set->packet.size < kt_tacocat_packet_minimum_d) { set->status = F_status_set_error(F_packet_too_large); - set->flag = 0; + } + else { + set->status = F_status_set_error(F_packet_too_small); + } - kt_tacocat_print_error_on_buffer_too_large(&main->program.error, kt_tacocat_receive_s, set->network, main->setting.max_buffer, set->packet.size); + kt_tacocat_print_error_on_packet_invalid(&main->program.error, kt_tacocat_receive_s, set->network); - return; - } + return; } set->flag |= kt_tacocat_socket_flag_receive_block_payload_e; diff --git a/sources/c/tacocat/main/send.c b/sources/c/tacocat/main/send.c index 6c1e54f..4a7ee2c 100644 --- a/sources/c/tacocat/main/send.c +++ b/sources/c/tacocat/main/send.c @@ -282,17 +282,23 @@ extern "C" { } if (set->flag == kt_tacocat_socket_flag_send_connect_e) { - // @fixme this is already performed, so do not do this here, the whole kt_tacocat_socket_flag_send_connect_e stage and kt_tacocat_send_connect_s should be removed. - //set->status = f_socket_connect(set->socket); - //macro_kt_send_process_handle_error_exit_1(main, f_socket_connect, kt_tacocat_send_connect_s, set->network, set->status, set->name, set->flag); + if (set->socket.id == -1) { + set->status = f_socket_connect(&set->socket); + macro_kt_send_process_handle_error_exit_1(main, f_socket_connect, kt_tacocat_send_connect_s, set->network, set->status, set->name, set->flag); + } + + if (set->socket.id_data == -1) { + set->socket.id_data = set->socket.id; + } - //set->socket.id_data = set->socket.id; set->flag = kt_tacocat_socket_flag_send_header_e; } if (set->flag == kt_tacocat_socket_flag_send_header_e) { size_t written = 0; + set->socket.size_write = set->size_done + set->size_block > set->header.used ? set->header.used - set->size_done : set->size_block; + set->status = f_socket_write_stream(&set->socket, 0, (void *) (set->header.string + set->size_done), &written); macro_kt_send_process_handle_error_exit_1(main, f_socket_write_stream, kt_tacocat_send_header_s, set->network, set->status, set->name, set->flag); @@ -313,6 +319,8 @@ extern "C" { if (set->flag == kt_tacocat_socket_flag_send_payload_e) { size_t written = 0; + set->socket.size_write = set->size_done + set->size_block > set->buffer.used ? set->buffer.used - set->size_done : set->size_block; + set->status = f_socket_write_stream(&set->socket, 0, (void *) (set->buffer.string + set->size_done), &written); macro_kt_send_process_handle_error_exit_1(main, f_socket_write_stream, kt_tacocat_send_payload_s, set->network, set->status, set->name, set->flag); -- 1.8.3.1