Skip to content

Commit

Permalink
fix: Changed some code to be cross platform
Browse files Browse the repository at this point in the history
Changed some code to be cross platform.
  • Loading branch information
zachhildreth committed Jun 25, 2020
1 parent 53d7547 commit fba5666
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions src/wallet/wallet_rpc_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3383,15 +3383,11 @@ namespace tools
}
//------------------------------------------------------------------------------------------------------------------------------

#define get_current_UTC_time(current_date_and_time,current_UTC_date_and_time) \
time(&current_date_and_time); \
gmtime_r(&current_date_and_time,&current_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";

Expand All @@ -3401,23 +3397,25 @@ 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(&current_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
{
std::cout << "Waiting until the next valid data interval, this will be at the beginning of the hour";

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(&current_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;
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit fba5666

Please sign in to comment.