Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakio815 committed Jan 23, 2025
1 parent 860520f commit fcf63ce
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 27 deletions.
3 changes: 0 additions & 3 deletions core/federated/RTI/rti_remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -1299,10 +1299,7 @@ static int receive_udp_message_and_set_up_clock_sync(netdrv_t* fed_netdrv, uint1
// Initialize the UDP_addr field of the federate struct
fed->UDP_addr.sin_family = AF_INET;
fed->UDP_addr.sin_port = htons(federate_UDP_port_number);
#ifdef COMM_TYPE_TCP
fed->UDP_addr.sin_addr = *get_ip_addr(fed_netdrv);
#elif
#endif
}
} else {
// Disable clock sync after initial round.
Expand Down
3 changes: 0 additions & 3 deletions core/federated/RTI/rti_remote.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ typedef struct federate_info_t {
// to a request for stop from the RTI. Used to prevent double-counting
// a federate when handling lf_request_stop().
lf_thread_t thread_id; // The ID of the thread handling communication with this federate.

netdrv_t* fed_netdrv; // The netdriver that the RTI handling each federate.

int socket; // The TCP socket descriptor for communicating with this federate.
struct sockaddr_in UDP_addr; // The UDP address for the federate.
bool clock_synchronization_enabled; // Indicates the status of clock synchronization
// for this federate. Enabled by default.
Expand Down
3 changes: 2 additions & 1 deletion core/federated/federate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1923,13 +1923,14 @@ void lf_create_server(int specified_port) {
assert(specified_port <= UINT16_MAX && specified_port >= 0);

netdrv_t* server_netdrv = initialize_netdrv();
//TODO: Check.
set_server_port(server_netdrv, specified_port);

if (create_server(server_netdrv, false)) {
lf_print_error_system_failure("RTI failed to create server: %s.", strerror(errno));
};
_fed.server_netdrv = server_netdrv;
// Get the final server port set.
// Get the final server port to send to the RTI on an MSG_TYPE_ADDRESS_ADVERTISEMENT message.
int32_t server_port = get_my_port(server_netdrv);

LF_PRINT_LOG("Server for communicating with other federates started using port %d.", server_port);
Expand Down
18 changes: 0 additions & 18 deletions network/api/socket_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,24 +104,6 @@ typedef struct socket_priv_t {
*/
int create_real_time_tcp_socket_errexit();

/**
* Set the socket timeout options.
* @param socket_descriptor The file descriptor of the socket on which to set options.
* @param timeout_time A pointer to a `struct timeval` that specifies the timeout duration
* for socket operations (receive and send).
*/
void set_socket_timeout_option(int socket_descriptor, struct timeval* timeout_time);

/**
* Assign a port to the socket, and bind the socket.
*
* @param socket_descriptor The file descriptor of the socket to be bound to an address and port.
* @param specified_port The port number to bind the socket to.
* @param increment_port_on_retry Boolean to retry port increment.
* @return The final port number used.
*/
int set_socket_bind_option(int socket_descriptor, uint16_t specified_port, bool increment_port_on_retry);

/**
* @brief Create a TCP server that listens for socket connections.
*
Expand Down
18 changes: 16 additions & 2 deletions network/impl/src/socket_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ int create_real_time_tcp_socket_errexit() {
return sock;
}

void set_socket_timeout_option(int socket_descriptor, struct timeval* timeout_time) {
/**
* Set the socket timeout options.
* @param socket_descriptor The file descriptor of the socket on which to set options.
* @param timeout_time A pointer to a `struct timeval` that specifies the timeout duration
* for socket operations (receive and send).
*/
static void set_socket_timeout_option(int socket_descriptor, struct timeval* timeout_time) {
// Set the option for this socket to reuse the same address
int true_variable = 1; // setsockopt() requires a reference to the value assigned to an option
if (setsockopt(socket_descriptor, SOL_SOCKET, SO_REUSEADDR, &true_variable, sizeof(int32_t)) < 0) {
Expand All @@ -67,7 +73,15 @@ void set_socket_timeout_option(int socket_descriptor, struct timeval* timeout_ti
}
}

int set_socket_bind_option(int socket_descriptor, uint16_t specified_port, bool increment_port_on_retry) {
/**
* Assign a port to the socket, and bind the socket.
*
* @param socket_descriptor The file descriptor of the socket to be bound to an address and port.
* @param specified_port The port number to bind the socket to.
* @param increment_port_on_retry Boolean to retry port increment.
* @return The final port number used.
*/
static int set_socket_bind_option(int socket_descriptor, uint16_t specified_port, bool increment_port_on_retry) {
// Server file descriptor.
struct sockaddr_in server_fd;
// Zero out the server address structure.
Expand Down

0 comments on commit fcf63ce

Please sign in to comment.