From 59446d97934d70d5834513f58b3dc31ab145b527 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Tue, 28 Nov 2023 22:23:41 -0600 Subject: [PATCH] Progress: Further work in TacocaT. The socket id and id_data descriptors need to be initialized to -1 and not 0. Make sure they are setup after allocation and after processing (or after disconnect). Provide more verbose error reporting that reports the particular block step the send fails on. The receive is not yet updated to do the same but in the future it should be updated to do so. --- sources/c/tacocat/main/common.c | 2 ++ sources/c/tacocat/main/common/define.h | 4 ++-- sources/c/tacocat/main/common/string.c | 8 ++++++++ sources/c/tacocat/main/common/string.h | 24 ++++++++++++++++++++++++ sources/c/tacocat/main/process.c | 6 ++++++ sources/c/tacocat/main/send.c | 29 ++++++++++++++++------------- 6 files changed, 58 insertions(+), 15 deletions(-) diff --git a/sources/c/tacocat/main/common.c b/sources/c/tacocat/main/common.c index 23e059a..79de62d 100644 --- a/sources/c/tacocat/main/common.c +++ b/sources/c/tacocat/main/common.c @@ -346,6 +346,8 @@ extern "C" { sets[i]->array[j].packet.payload.stop = 0; sets[i]->array[j].retry = 0; 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].write_state.conversion = f_conversion_data_base_10_c; sets[i]->array[j].write_state.cache = &sets[i]->array[j].cache; diff --git a/sources/c/tacocat/main/common/define.h b/sources/c/tacocat/main/common/define.h index df04868..4f07a0a 100644 --- a/sources/c/tacocat/main/common/define.h +++ b/sources/c/tacocat/main/common/define.h @@ -180,9 +180,9 @@ extern "C" { return; \ } - #define macro_kt_send_process_handle_error_exit_1(main, method, network, status, name, flag) \ + #define macro_kt_send_process_handle_error_exit_1(main, method, on, network, status, name, flag) \ if (F_status_is_error(status)) { \ - kt_tacocat_print_error_on(&main->program.error, macro_kt_tacocat_f(method), kt_tacocat_send_s, network, status, name); \ + kt_tacocat_print_error_on(&main->program.error, macro_kt_tacocat_f(method), on, network, status, name); \ \ return F_done_not; \ } diff --git a/sources/c/tacocat/main/common/string.c b/sources/c/tacocat/main/common/string.c index 0872b2f..acd2ec0 100644 --- a/sources/c/tacocat/main/common/string.c +++ b/sources/c/tacocat/main/common/string.c @@ -26,6 +26,14 @@ extern "C" { const f_string_static_t kt_tacocat_network_or_socket_s = macro_f_string_static_t_initialize_1(KT_TACOCAT_network_or_socket_s, 0, KT_TACOCAT_network_or_socket_s_length); const f_string_static_t kt_tacocat_receive_s = macro_f_string_static_t_initialize_1(KT_TACOCAT_receive_s, 0, KT_TACOCAT_receive_s_length); const f_string_static_t kt_tacocat_send_s = macro_f_string_static_t_initialize_1(KT_TACOCAT_send_s, 0, KT_TACOCAT_send_s_length); + const f_string_static_t kt_tacocat_send_build_s = macro_f_string_static_t_initialize_1(KT_TACOCAT_send_build_s, 0, KT_TACOCAT_send_build_s_length); + const f_string_static_t kt_tacocat_send_combine_s = macro_f_string_static_t_initialize_1(KT_TACOCAT_send_combine_s, 0, KT_TACOCAT_send_combine_s_length); + const f_string_static_t kt_tacocat_send_connect_s = macro_f_string_static_t_initialize_1(KT_TACOCAT_send_connect_s, 0, KT_TACOCAT_send_connect_s_length); + const f_string_static_t kt_tacocat_send_done_s = macro_f_string_static_t_initialize_1(KT_TACOCAT_send_done_s, 0, KT_TACOCAT_send_done_s_length); + const f_string_static_t kt_tacocat_send_file_s = macro_f_string_static_t_initialize_1(KT_TACOCAT_send_file_s, 0, KT_TACOCAT_send_file_s_length); + const f_string_static_t kt_tacocat_send_header_s = macro_f_string_static_t_initialize_1(KT_TACOCAT_send_header_s, 0, KT_TACOCAT_send_header_s_length); + const f_string_static_t kt_tacocat_send_payload_s = macro_f_string_static_t_initialize_1(KT_TACOCAT_send_payload_s, 0, KT_TACOCAT_send_payload_s_length); + const f_string_static_t kt_tacocat_send_size_s = macro_f_string_static_t_initialize_1(KT_TACOCAT_send_size_s, 0, KT_TACOCAT_send_size_s_length); const f_string_static_t kt_tacocat_socket_s = macro_f_string_static_t_initialize_1(KT_TACOCAT_socket_s, 0, KT_TACOCAT_socket_s_length); const f_string_static_t kt_tacocat_tacocat_s = macro_f_string_static_t_initialize_1(KT_TACOCAT_tacocat_s, 0, KT_TACOCAT_tacocat_s_length); const f_string_static_t kt_tacocat_two_s = macro_f_string_static_t_initialize_1(KT_TACOCAT_two_s, 0, KT_TACOCAT_two_s_length); diff --git a/sources/c/tacocat/main/common/string.h b/sources/c/tacocat/main/common/string.h index df04c10..bcb0713 100644 --- a/sources/c/tacocat/main/common/string.h +++ b/sources/c/tacocat/main/common/string.h @@ -80,6 +80,14 @@ extern "C" { #define KT_TACOCAT_network_or_socket_s "network / socket" #define KT_TACOCAT_receive_s "receive" #define KT_TACOCAT_send_s "send" + #define KT_TACOCAT_send_build_s "send build" + #define KT_TACOCAT_send_combine_s "send combine" + #define KT_TACOCAT_send_connect_s "send connect" + #define KT_TACOCAT_send_done_s "send done" + #define KT_TACOCAT_send_file_s "send file" + #define KT_TACOCAT_send_header_s "send header" + #define KT_TACOCAT_send_payload_s "send payload" + #define KT_TACOCAT_send_size_s "send size" #define KT_TACOCAT_socket_s "socket" #define KT_TACOCAT_tacocat_s "tacocat" #define KT_TACOCAT_two_s "two" @@ -92,6 +100,14 @@ extern "C" { #define KT_TACOCAT_network_or_socket_s_length 16 #define KT_TACOCAT_receive_s_length 7 #define KT_TACOCAT_send_s_length 4 + #define KT_TACOCAT_send_build_s_length 19 + #define KT_TACOCAT_send_combine_s_length 12 + #define KT_TACOCAT_send_connect_s_length 12 + #define KT_TACOCAT_send_done_s_length 9 + #define KT_TACOCAT_send_file_s_length 9 + #define KT_TACOCAT_send_header_s_length 11 + #define KT_TACOCAT_send_payload_s_length 12 + #define KT_TACOCAT_send_size_s_length 9 #define KT_TACOCAT_socket_s_length 6 #define KT_TACOCAT_tacocat_s_length 7 #define KT_TACOCAT_two_s_length 3 @@ -104,6 +120,14 @@ extern "C" { extern const f_string_static_t kt_tacocat_network_or_socket_s; extern const f_string_static_t kt_tacocat_receive_s; extern const f_string_static_t kt_tacocat_send_s; + extern const f_string_static_t kt_tacocat_send_build_s; + extern const f_string_static_t kt_tacocat_send_combine_s; + extern const f_string_static_t kt_tacocat_send_connect_s; + extern const f_string_static_t kt_tacocat_send_done_s; + extern const f_string_static_t kt_tacocat_send_file_s; + extern const f_string_static_t kt_tacocat_send_header_s; + extern const f_string_static_t kt_tacocat_send_payload_s; + extern const f_string_static_t kt_tacocat_send_size_s; extern const f_string_static_t kt_tacocat_socket_s; extern const f_string_static_t kt_tacocat_tacocat_s; extern const f_string_static_t kt_tacocat_two_s; diff --git a/sources/c/tacocat/main/process.c b/sources/c/tacocat/main/process.c index 54acfb2..72a0fcc 100644 --- a/sources/c/tacocat/main/process.c +++ b/sources/c/tacocat/main/process.c @@ -239,6 +239,9 @@ extern "C" { continue; } + // The id_data socket ID is the same when sending (writing) to the socket. + main->setting.send.array[i].socket.id_data = main->setting.send.array[i].socket.id; + // Make the socket re-usable. { value_socket = 1; @@ -349,6 +352,9 @@ extern "C" { if (F_status_is_error(status)) { f_socket_disconnect(&sets->array[i].socket, f_socket_close_read_write_e); } + + sets->array[i].socket.id = -1; + sets->array[i].socket.id_data = -1; } // for } diff --git a/sources/c/tacocat/main/send.c b/sources/c/tacocat/main/send.c index e082d5c..ca1be97 100644 --- a/sources/c/tacocat/main/send.c +++ b/sources/c/tacocat/main/send.c @@ -76,8 +76,6 @@ extern "C" { if (!main || !set) return F_status_set_error(F_parameter); - // @todo this needs a max retries for sending without error, possibly resetting depending on the part (flag). - if (!set->flag) { set->abstruses.used = 0; set->buffer.used = 0; @@ -101,7 +99,7 @@ extern "C" { } if (F_status_is_error(set->status)) { - macro_kt_send_process_handle_error_exit_1(main, f_memory_array_increase_by, set->network, set->status, set->name, set->flag); + macro_kt_send_process_handle_error_exit_1(main, f_memory_array_increase_by, kt_tacocat_send_s, set->network, set->status, set->name, set->flag); } // Index 0 is the status. @@ -151,6 +149,8 @@ extern "C" { // Keep error bit but set state to done to designate that nothing else is to be done. set->status = F_status_set_error(F_done); + set->socket.id = -1; + set->socket.id_data = -1; kt_tacocat_print_error_on_max_retries(&main->program.error, kt_tacocat_send_s, set->network, set->name); @@ -165,7 +165,7 @@ extern "C" { set->status = f_file_size_by_id(set->file, &total); if (F_status_is_error(set->status)) { - kt_tacocat_print_error_on_file_receive(&main->program.error, macro_kt_tacocat_f(f_file_size_by_id), kt_tacocat_send_s, set->network, set->status, set->name, f_file_operation_open_s); + kt_tacocat_print_error_on_file_receive(&main->program.error, macro_kt_tacocat_f(f_file_size_by_id), kt_tacocat_send_size_s, set->network, set->status, set->name, f_file_operation_open_s); return F_done_not; } @@ -173,7 +173,7 @@ extern "C" { if ((f_number_unsigned_t) total > F_number_t_size_unsigned_d) { set->status = F_status_set_error(F_too_large); - kt_tacocat_print_error_on_file_too_large(&main->program.error, set->name, kt_tacocat_send_s, set->network, F_number_t_size_unsigned_d, set->abstruses.array[4].value.is.a_unsigned); + kt_tacocat_print_error_on_file_too_large(&main->program.error, set->name, kt_tacocat_send_size_s, set->network, F_number_t_size_unsigned_d, set->abstruses.array[4].value.is.a_unsigned); return F_done_not; } @@ -208,7 +208,7 @@ extern "C" { } if (F_status_is_error(set->status)) { - macro_kt_send_process_handle_error_exit_1(main, f_file_read_block, set->network, set->status, set->name, set->flag); + macro_kt_send_process_handle_error_exit_1(main, f_file_read_block, kt_tacocat_send_file_s, set->network, set->status, set->name, set->flag); } set->abstruses.array[2].value.is.a_unsigned = set->buffer.used - f_fss_payload_object_payload_s.used - f_fss_payload_object_end_s.used; @@ -224,7 +224,7 @@ extern "C" { state_local.data = &set->write_state; fl_fss_payload_header_map(set->abstruses, &set->headers, &state_local); - macro_kt_send_process_handle_error_exit_1(main, fl_fss_payload_header_map, set->network, state_local.status, set->name, set->flag); + macro_kt_send_process_handle_error_exit_1(main, fl_fss_payload_header_map, kt_tacocat_send_build_s, set->network, state_local.status, set->name, set->flag); set->flag = kt_tacocat_socket_flag_send_combine_e; } @@ -274,7 +274,7 @@ extern "C" { } if (F_status_is_error_not(set->status)) { - macro_kt_send_process_handle_error_exit_1(main, f_string_dynamic_append, set->network, set->status, set->name, set->flag); + macro_kt_send_process_handle_error_exit_1(main, f_string_dynamic_append, kt_tacocat_send_combine_s, set->network, set->status, set->name, set->flag); } set->header.string[set->header.used] = 0; @@ -283,8 +283,9 @@ extern "C" { if (set->flag == kt_tacocat_socket_flag_send_connect_e) { set->status = f_socket_connect(set->socket); - macro_kt_send_process_handle_error_exit_1(main, f_socket_connect, set->network, set->status, set->name, set->flag); + 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); + set->socket.id_data = set->socket.id; set->flag = kt_tacocat_socket_flag_send_header_e; } @@ -292,7 +293,7 @@ extern "C" { size_t written = 0; 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, set->network, set->status, set->name, set->flag); + 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); set->size_done += written; @@ -312,7 +313,7 @@ extern "C" { size_t written = 0; 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, set->network, set->status, set->name, set->flag); + 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); set->size_done += written; @@ -335,15 +336,17 @@ extern "C" { set->status = f_file_close(&set->file); if (F_status_is_error(set->status)) { - kt_tacocat_print_warning_on_file(&main->program.warning, macro_kt_tacocat_f(f_file_close), kt_tacocat_send_s, set->network, set->status, set->name, f_file_operation_close_s); + kt_tacocat_print_warning_on_file(&main->program.warning, macro_kt_tacocat_f(f_file_close), kt_tacocat_send_done_s, set->network, set->status, set->name, f_file_operation_close_s); } set->status = f_socket_disconnect(&set->socket, f_socket_close_write_e); if (F_status_is_error(set->status)) { - kt_tacocat_print_warning_on_file(&main->program.warning, macro_kt_tacocat_f(f_socket_disconnect), kt_tacocat_send_s, set->network, set->status, set->name, f_file_operation_close_s); + kt_tacocat_print_warning_on_file(&main->program.warning, macro_kt_tacocat_f(f_socket_disconnect), kt_tacocat_send_done_s, set->network, set->status, set->name, f_file_operation_close_s); } + set->socket.id = -1; + set->socket.id_data = -1; set->status = F_okay; return F_done; -- 1.8.3.1