Browse Source

Replace usleep() and random()

cl-refactor
Eric Lombrozo 11 years ago
parent
commit
923553dfa9
  1. 2
      eth/main.cpp
  2. 4
      libethereum/Client.cpp
  3. 2
      libethereum/PeerNetwork.cpp
  4. 2
      libethereum/UPnP.cpp
  5. 2
      test/peer.cpp

2
eth/main.cpp

@ -236,7 +236,7 @@ int main(int argc, char** argv)
c.stopMining(); c.stopMining();
else else
c.startMining(); c.startMining();
usleep(100000); std::this_thread::sleep_for(std::chrono::microseconds(100000));
} }
} }

4
libethereum/Client.cpp

@ -64,7 +64,7 @@ Client::~Client()
if (m_workState == Active) if (m_workState == Active)
m_workState = Deleting; m_workState = Deleting;
while (m_workState != Deleted) while (m_workState != Deleted)
usleep(10000); std::this_thread::sleep_for(std::chrono::microseconds(10000));
} }
void Client::startNetwork(short _listenPort, std::string const& _seedHost, short _port, NodeMode _mode, unsigned _peers, string const& _publicIP, bool _upnp) void Client::startNetwork(short _listenPort, std::string const& _seedHost, short _port, NodeMode _mode, unsigned _peers, string const& _publicIP, bool _upnp)
@ -158,7 +158,7 @@ void Client::work()
} }
} }
else else
usleep(100000); std::this_thread::sleep_for(std::chrono::microseconds(100000));
} }
void Client::lock() void Client::lock()

2
libethereum/PeerNetwork.cpp

@ -919,7 +919,7 @@ bool PeerServer::process(BlockChain& _bc, TransactionQueue& _tq, Overlay& _o)
std::vector<PeerInfo> PeerServer::peers() const std::vector<PeerInfo> PeerServer::peers() const
{ {
const_cast<PeerServer*>(this)->pingAll(); const_cast<PeerServer*>(this)->pingAll();
usleep(200000); std::this_thread::sleep_for(std::chrono::microseconds(200000));
std::vector<PeerInfo> ret; std::vector<PeerInfo> ret;
for (auto& i: m_peers) for (auto& i: m_peers)
if (auto j = i.lock()) if (auto j = i.lock())

2
libethereum/UPnP.cpp

@ -117,7 +117,7 @@ int UPnP::addRedirect(char const* addr, int port)
// Failed - now try (random external, port internal) and cycle up to 10 times. // Failed - now try (random external, port internal) and cycle up to 10 times.
for (uint i = 0; i < 10; ++i) for (uint i = 0; i < 10; ++i)
{ {
port = random() % 65535 - 1024 + 1024; port = rand() % 65535 - 1024 + 1024;
sprintf(port_str, "%d", port); sprintf(port_str, "%d", port);
if (!UPNP_AddPortMapping(m_urls->controlURL, m_data->first.servicetype, NULL, port_str, addr, "ethereum", "TCP", NULL, NULL)) if (!UPNP_AddPortMapping(m_urls->controlURL, m_data->first.servicetype, NULL, port_str, addr, "ethereum", "TCP", NULL, NULL))
return port; return port;

2
test/peer.cpp

@ -53,7 +53,7 @@ int peerTest(int argc, char** argv)
for (int i = 0; ; ++i) for (int i = 0; ; ++i)
{ {
usleep(100000); std::this_thread::sleep_for(std::chrono::microseconds(100000));
pn.process(ch); pn.process(ch);
if (!(i % 10)) if (!(i % 10))
pn.pingAll(); pn.pingAll();

Loading…
Cancel
Save