Commit ac447032 authored by aligungr's avatar aligungr

IPv6 support

parent 6699b76d
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
#include <atomic> #include <atomic>
#include <csignal> #include <csignal>
#include <cstdio> #include <cstdio>
#include <cstdlib>
#include <ctime>
#include <exception> #include <exception>
#include <vector> #include <vector>
...@@ -37,6 +39,8 @@ void Initialize() ...@@ -37,6 +39,8 @@ void Initialize()
if (g_instanceCount++ != 0) if (g_instanceCount++ != 0)
std::terminate(); std::terminate();
srand(time(nullptr));
std::signal(SIGTERM, BaseSignalHandler); std::signal(SIGTERM, BaseSignalHandler);
std::signal(SIGINT, BaseSignalHandler); std::signal(SIGINT, BaseSignalHandler);
} }
......
...@@ -273,20 +273,12 @@ Socket Socket::Select(const std::vector<Socket> &readSockets, const std::vector< ...@@ -273,20 +273,12 @@ Socket Socket::Select(const std::vector<Socket> &readSockets, const std::vector<
std::vector<Socket> rs, ws; std::vector<Socket> rs, ws;
Select(readSockets, writeSockets, rs, ws, timeout); Select(readSockets, writeSockets, rs, ws, timeout);
// Return a socket choosen at random from selection // Return a socket chosen at random from selection to avoid starvation
// to avoid starvation auto r = static_cast<size_t>(rand());
std::default_random_engine generator;
if (!rs.empty()) if (!rs.empty())
{ return rs[r % rs.size()];
std::uniform_int_distribution<int> drs(0, rs.size() - 1);
return rs[drs(generator)];
}
if (!ws.empty()) if (!ws.empty())
{ return ws[r % ws.size()];
std::uniform_int_distribution<int> dws(0, ws.size() - 1);
return rs[dws(generator)];
}
return {}; return {};
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment