From af315d21f28759978168593ec9a5f694d6c80a3e Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Mon, 10 Jul 2023 22:04:58 -0500 Subject: [PATCH] Progress: Further work in TacocaT. Get listen working. Setup poll handler. --- sources/c/tacocat/main/common.c | 10 ++++++++-- sources/c/tacocat/main/common/print.c | 1 + sources/c/tacocat/main/common/print.h | 1 + sources/c/tacocat/main/common/type.c | 1 + sources/c/tacocat/main/common/type.h | 8 +++++++- sources/c/tacocat/main/process.c | 16 ++++++++++++++++ 6 files changed, 34 insertions(+), 3 deletions(-) diff --git a/sources/c/tacocat/main/common.c b/sources/c/tacocat/main/common.c index ff6eaca..074994b 100644 --- a/sources/c/tacocat/main/common.c +++ b/sources/c/tacocat/main/common.c @@ -208,6 +208,7 @@ extern "C" { sets[i]->names.used = 0; sets[i]->buffers.used = 0; + sets[i]->polls.used = 0; main->setting.state.status = f_string_dynamics_increase_by(main->program.parameters.array[parameters[i]].values.used / 2, &sets[i]->names); @@ -229,6 +230,10 @@ extern "C" { macro_setting_load_handle_send_receive_error_continue_1(f_statuss_increase_by); + main->setting.state.status = f_polls_increase_by(main->program.parameters.array[parameters[i]].values.used / 2, &sets[i]->polls); + + macro_setting_load_handle_send_receive_error_continue_1(f_polls_increase_by); + for (j = 0; j < main->program.parameters.array[parameters[i]].values.used; j += 2) { // First parameter value represents the network address or the socket file path. @@ -261,7 +266,7 @@ extern "C" { sets[i]->names.array[j].string[sets[i]->names.array[j].used] = 0; sets[i]->sockets.array[j].domain = f_socket_protocol_family_local_e; sets[i]->sockets.array[j].protocol = f_socket_protocol_tcp_e; - sets[i]->sockets.array[j].type = f_socket_address_family_local_e; + sets[i]->sockets.array[j].type = f_socket_type_stream_e; sets[i]->sockets.array[j].name = sets[i]->names.array[j]; } else if (main->setting.flag & kt_tacocat_main_flag_resolve_classic_e) { @@ -388,7 +393,7 @@ extern "C" { } sets[i]->sockets.array[j].protocol = f_socket_protocol_tcp_e; - sets[i]->sockets.array[j].type = host.h_addrtype; + sets[i]->sockets.array[j].type = f_socket_type_stream_e; if (host.h_addrtype == f_socket_address_family_inet4_e) { sets[i]->sockets.array[j].domain = f_socket_protocol_family_inet4_e; @@ -406,6 +411,7 @@ extern "C" { } ++sets[i]->files.used; + ++sets[i]->polls.used; ++sets[i]->sockets.used; ++sets[i]->statuss.used; ++sets[i]->names.used; diff --git a/sources/c/tacocat/main/common/print.c b/sources/c/tacocat/main/common/print.c index 7b44ec8..ff8f56b 100644 --- a/sources/c/tacocat/main/common/print.c +++ b/sources/c/tacocat/main/common/print.c @@ -11,6 +11,7 @@ extern "C" { "f_files_increase_by", "f_network_from_ip_name", "f_network_is_ip_address", + "f_polls_increase_by", "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 75dc03e..d8dfe2d 100644 --- a/sources/c/tacocat/main/common/print.h +++ b/sources/c/tacocat/main/common/print.h @@ -44,6 +44,7 @@ extern "C" { kt_tacocat_f_f_files_increase_by_e, 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_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/common/type.c b/sources/c/tacocat/main/common/type.c index bd51e72..9afdfc2 100644 --- a/sources/c/tacocat/main/common/type.c +++ b/sources/c/tacocat/main/common/type.c @@ -38,6 +38,7 @@ extern "C" { } // for f_files_resize(0, &sets[i]->files); + f_polls_resize(0, &sets[i]->polls); f_sockets_resize(0, &sets[i]->sockets); f_statuss_resize(0, &sets[i]->statuss); diff --git a/sources/c/tacocat/main/common/type.h b/sources/c/tacocat/main/common/type.h index 7a8c116..1ca5726 100644 --- a/sources/c/tacocat/main/common/type.h +++ b/sources/c/tacocat/main/common/type.h @@ -22,8 +22,10 @@ extern "C" { * block_size: The size in bytes to used to represent a block when sending or receiving packets. * * files: An array of files for each socket. + * polls: An array of sockets to poll, specifically for passing to f_file_poll(). * sockets: An array of the network sockets. * statuss: An array of statuses for each socket. + * * names: An array of names for each socket. * buffers: An array of buffers for sending or receiving data between clients for each socket. */ @@ -32,8 +34,10 @@ extern "C" { f_number_unsigned_t block_size; f_files_t files; + f_polls_t polls; f_sockets_t sockets; f_statuss_t statuss; + f_string_dynamics_t names; f_string_dynamics_t buffers; } kt_tacocat_socket_set_t; @@ -42,6 +46,7 @@ extern "C" { { \ kt_tacocat_block_size_d, \ f_files_t_initialize, \ + f_polls_t_initialize, \ f_sockets_t_initialize, \ f_statuss_t_initialize, \ f_string_dynamics_t_initialize, \ @@ -52,6 +57,7 @@ extern "C" { { \ block_size, \ f_files_t_initialize, \ + f_polls_t_initialize, \ f_sockets_t_initialize, \ f_statuss_t_initialize, \ f_string_dynamics_t_initialize, \ @@ -73,7 +79,7 @@ extern "C" { * receive: The socket set for receiving data receive clients. * send: The socket set for sending data send clients. * - * buffer: A string buffer used for caching purposes. + * buffer: A string buffer used for caching purposes. */ #ifndef _di_kt_tacocat_setting_t_ typedef struct { diff --git a/sources/c/tacocat/main/process.c b/sources/c/tacocat/main/process.c index 0fbe9a3..c7f71d9 100644 --- a/sources/c/tacocat/main/process.c +++ b/sources/c/tacocat/main/process.c @@ -176,9 +176,25 @@ extern "C" { continue; } + + if (main->setting.receive.sockets.array[i].id == -1) { + main->setting.receive.polls.array[i].fd = -1; + main->setting.receive.polls.array[i].events = 0; + main->setting.receive.polls.array[i].revents = 0; + } + else { + main->setting.receive.polls.array[i].fd = main->setting.receive.sockets.array[i].id; + main->setting.receive.polls.array[i].events = f_poll_read_e | f_poll_urgent_e; + main->setting.receive.polls.array[i].revents = 0; + } } // for if (F_status_is_error_not(main->setting.state.status)) { + // @todo this is where another process should poll/wait for connections and such (in another thread/fork). + main->setting.state.status = f_file_poll(main->setting.receive.polls, 9000); // @todo temporarily set to 9 second(s). + + // @todo handle errors, but this will be in a fork/thread. + main->setting.state.status = F_none; } } -- 1.8.3.1