From fba566649c98e6c76e804b553e18f4b9510cd173 Mon Sep 17 00:00:00 2001 From: zachhildreth Date: Thu, 25 Jun 2020 02:41:45 +0000 Subject: [PATCH] fix: Changed some code to be cross platform Changed some code to be cross platform. --- src/wallet/wallet_rpc_server.cpp | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index de05bf0665d..05068f53678 100755 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -3383,15 +3383,11 @@ namespace tools } //------------------------------------------------------------------------------------------------------------------------------ -#define get_current_UTC_time(current_date_and_time,current_UTC_date_and_time) \ -time(¤t_date_and_time); \ -gmtime_r(¤t_date_and_time,¤t_UTC_date_and_time); - void sync_minutes_and_seconds(const int SETTINGS) { // Variables - time_t current_date_and_time; - struct tm current_UTC_date_and_time; + std::time_t current_date_and_time; + std::tm* current_UTC_date_and_time; std::cout << "Waiting until the next valid data interval, this will be less than 5 minutes"; @@ -3401,9 +3397,10 @@ void sync_minutes_and_seconds(const int SETTINGS) do { - nanosleep((const struct timespec[]){{0, 200000000L}}, NULL); - get_current_UTC_time(current_date_and_time,current_UTC_date_and_time); - } while (current_UTC_date_and_time.tm_min % BLOCK_TIME != 2 && current_UTC_date_and_time.tm_min % BLOCK_TIME != 3); + std::this_thread::sleep_for(std::chrono::milliseconds(200)); + current_date_and_time = std::time(0); + current_UTC_date_and_time = std::gmtime(¤t_date_and_time); + } while (current_UTC_date_and_time->tm_min % BLOCK_TIME != 2 && current_UTC_date_and_time->tm_min % BLOCK_TIME != 3); } else { @@ -3411,13 +3408,14 @@ void sync_minutes_and_seconds(const int SETTINGS) do { - nanosleep((const struct timespec[]){{0, 200000000L}}, NULL); - get_current_UTC_time(current_date_and_time,current_UTC_date_and_time); - } while (current_UTC_date_and_time.tm_min != 2); + std::this_thread::sleep_for(std::chrono::milliseconds(200)); + current_date_and_time = std::time(0); + current_UTC_date_and_time = std::gmtime(¤t_date_and_time); + } while (current_UTC_date_and_time->tm_min != 2); } // wait a few more seconds due to not all clocks being synced at the same second - sleep(3); + std::this_thread::sleep_for(std::chrono::milliseconds(3000)); return; } @@ -3474,7 +3472,7 @@ bool wallet_rpc_server::on_vote(const wallet_rpc::COMMAND_RPC_VOTE::request& req for (count = 0; string.find("|") == std::string::npos && count < MAXIMUM_CONNECTION_TIMEOUT_SETTINGS; count++) { string = send_and_receive_data(network_data_nodes_list.network_data_nodes_IP_address[(int)(rand() % NETWORK_DATA_NODES_AMOUNT)],MESSAGE,SOCKET_CONNECTION_TIMEOUT_SETTINGS); - sleep(1); + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); } if (count == MAXIMUM_CONNECTION_TIMEOUT_SETTINGS) @@ -3636,7 +3634,7 @@ bool wallet_rpc_server::on_delegate_register(const wallet_rpc::COMMAND_RPC_DELEG for (count = 0; string.find("|") == std::string::npos && count < MAXIMUM_CONNECTION_TIMEOUT_SETTINGS; count++) { string = send_and_receive_data(network_data_nodes_list.network_data_nodes_IP_address[(int)(rand() % NETWORK_DATA_NODES_AMOUNT)],MESSAGE,SOCKET_CONNECTION_TIMEOUT_SETTINGS); - sleep(1); + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); } if (count == MAXIMUM_CONNECTION_TIMEOUT_SETTINGS) @@ -3828,7 +3826,7 @@ bool wallet_rpc_server::on_delegate_update(const wallet_rpc::COMMAND_RPC_DELEGAT for (count = 0; string.find("|") == std::string::npos && count < MAXIMUM_CONNECTION_TIMEOUT_SETTINGS; count++) { string = send_and_receive_data(network_data_nodes_list.network_data_nodes_IP_address[(int)(rand() % NETWORK_DATA_NODES_AMOUNT)],MESSAGE,SOCKET_CONNECTION_TIMEOUT_SETTINGS); - sleep(1); + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); } if (count == MAXIMUM_CONNECTION_TIMEOUT_SETTINGS)