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.
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;
}
* - 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.
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_
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);
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;
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;
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);
}
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;
}
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;
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;
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);