From d16de808b5ed202cbf66b0fd1be5d8135bce92be Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Mon, 11 Dec 2023 00:32:38 -0600 Subject: [PATCH] Progress: Further work in TacocaT. The F_pipe is being returned on socket write calls because the socket.address.inet4.sin_family (and probably the socket.address.inet4.sin_family) is not being set. The kt_tacocat_socket_flag_send_connect_e is not needed and is now removed. Use f_socket_close_fast_e in f_socket_disconnect(). Pass f_socket_flag_signal_not_e as a flag to f_socket_write_stream() so that a signal is not received if f_socket_write_stream() returns F_pipe. --- sources/c/tacocat/main/common.c | 2 ++ sources/c/tacocat/main/common/enumeration.h | 8 +++----- sources/c/tacocat/main/process.c | 28 ++++------------------------ sources/c/tacocat/main/send.c | 22 +++++----------------- 4 files changed, 14 insertions(+), 46 deletions(-) diff --git a/sources/c/tacocat/main/common.c b/sources/c/tacocat/main/common.c index 3cfbc50..7dbc150 100644 --- a/sources/c/tacocat/main/common.c +++ b/sources/c/tacocat/main/common.c @@ -521,11 +521,13 @@ extern "C" { if (host.h_addrtype == f_socket_address_family_inet4_e) { sets[i]->array[j].socket.domain = f_socket_protocol_family_inet4_e; + sets[i]->array[j].socket.address.inet4.sin_family = f_socket_address_family_inet4_e; sets[i]->array[j].socket.address.inet4.sin_port = htons((in_port_t) port); sets[i]->array[j].socket.address.inet4.sin_addr.s_addr = family.address.v4.s_addr; } else if (host.h_addrtype == f_socket_address_family_inet6_e) { sets[i]->array[j].socket.domain = f_socket_protocol_family_inet6_e; + sets[i]->array[j].socket.address.inet4.sin_family = f_socket_address_family_inet6_e; sets[i]->array[j].socket.address.inet6.sin6_port = htons((in_port_t) port); sets[i]->array[j].socket.address.inet6.sin6_addr = family.address.v6; } diff --git a/sources/c/tacocat/main/common/enumeration.h b/sources/c/tacocat/main/common/enumeration.h index 808e2ed..93ba773 100644 --- a/sources/c/tacocat/main/common/enumeration.h +++ b/sources/c/tacocat/main/common/enumeration.h @@ -151,7 +151,6 @@ extern "C" { * - file: Buffer the file. * - build: Build the header information. * - combine: Combine the built header information into a single buffer. - * - connect: Connect to the remote address. * - header: Send the header information. * - payload: Send the payload information. * - done: The entire Packet is sent. @@ -163,10 +162,9 @@ extern "C" { kt_tacocat_socket_flag_send_file_e = 0x2, kt_tacocat_socket_flag_send_build_e = 0x4, kt_tacocat_socket_flag_send_combine_e = 0x8, - kt_tacocat_socket_flag_send_connect_e = 0x10, - kt_tacocat_socket_flag_send_header_e = 0x20, - kt_tacocat_socket_flag_send_payload_e = 0x40, - kt_tacocat_socket_flag_send_done_e = 0x80, + kt_tacocat_socket_flag_send_header_e = 0x10, + kt_tacocat_socket_flag_send_payload_e = 0x20, + kt_tacocat_socket_flag_send_done_e = 0x40, }; // enum #endif // _di_kt_tacocat_socket_flag_send_e_ diff --git a/sources/c/tacocat/main/process.c b/sources/c/tacocat/main/process.c index 49945a3..6101791 100644 --- a/sources/c/tacocat/main/process.c +++ b/sources/c/tacocat/main/process.c @@ -227,31 +227,14 @@ extern "C" { continue; } - // Make the socket re-usable. - { - value_socket = 1; - - main->setting.send.array[i].status = f_socket_option_set(&main->setting.send.array[i].socket, SOL_SOCKET, f_socket_option_address_reuse_e | f_socket_option_port_reuse_e, &value_socket, sizeof(int)); - - if (F_status_is_error(main->setting.send.array[i].status)) { - main->setting.status_send = main->setting.send.array[i].status; - - kt_tacocat_print_error_status(&main->program.error, macro_kt_tacocat_f(f_socket_option_set), main->setting.status_send); - - 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; 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); - // 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)) { - main->setting.send.array[i].socket.id_data = main->setting.send.array[i].socket.id; - } - // Treat invalid file descriptor as an error as the descriptor should be valid at this point in time. if (main->setting.send.array[i].status == F_file_descriptor) { main->setting.send.array[i].status = F_status_set_error(F_file_descriptor); @@ -311,6 +294,7 @@ extern "C" { continue; } + // @fixme are send_polls even used yet? This should be used to listen for and catch a response from the receive end after sending. if (main->setting.send.array[i].socket.id == -1) { main->setting.send_polls.array[i].fd = -1; main->setting.send_polls.array[i].events = 0; @@ -343,11 +327,7 @@ extern "C" { f_file_close(&sets->array[i].file); f_file_close_id(&sets->array[i].socket.id_data); - status = f_socket_disconnect(&sets->array[i].socket, main->program.signal_received ? f_socket_close_fast_e : f_socket_close_read_write_e); - - if (F_status_is_error(status)) { - f_socket_disconnect(&sets->array[i].socket, f_socket_close_read_write_e); - } + f_socket_disconnect(&sets->array[i].socket, f_socket_close_fast_e); sets->array[i].socket.id = -1; sets->array[i].socket.id_data = -1; diff --git a/sources/c/tacocat/main/send.c b/sources/c/tacocat/main/send.c index 4a7ee2c..c468e8e 100644 --- a/sources/c/tacocat/main/send.c +++ b/sources/c/tacocat/main/send.c @@ -145,7 +145,7 @@ extern "C" { if (set->retry >= kt_tacocat_startup_retry_max_d) { f_file_close(&set->file); - f_socket_disconnect(&set->socket, f_socket_close_write_e); + f_socket_disconnect(&set->socket, f_socket_close_fast_e); // 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); @@ -278,19 +278,6 @@ extern "C" { } set->header.string[set->header.used] = 0; - set->flag = kt_tacocat_socket_flag_send_connect_e; - } - - if (set->flag == kt_tacocat_socket_flag_send_connect_e) { - 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->flag = kt_tacocat_socket_flag_send_header_e; } @@ -299,7 +286,8 @@ extern "C" { 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); + set->status = f_socket_write_stream(&set->socket, f_socket_flag_signal_not_e, (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); set->size_done += written; @@ -321,7 +309,7 @@ extern "C" { 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); + set->status = f_socket_write_stream(&set->socket, f_socket_flag_signal_not_e, (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); set->size_done += written; @@ -348,7 +336,7 @@ extern "C" { 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); + set->status = f_socket_disconnect(&set->socket, f_socket_close_fast_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_done_s, set->network, set->status, set->name, f_file_operation_close_s); -- 1.8.3.1