Set monitor connections to non-blocking

Better to just drop monitor connections when the quality is bad than to
risk blocking the shard thread.
This commit is contained in:
2020-12-05 23:16:09 +01:00
parent 6b257887b7
commit 53d8cb67ba
3 changed files with 15 additions and 1 deletions

View File

@@ -46,6 +46,16 @@ void Monitor::init() {
exit(1);
}
#ifdef _WIN32
unsigned long mode = 1;
if (ioctlsocket(listener, FIONBIO, &mode) != 0) {
#else
if (fcntl(listener, F_SETFL, (fcntl(listener, F_GETFL, 0) | O_NONBLOCK)) != 0) {
#endif
std::cerr << "[FATAL] OpenFusion: fcntl failed" << std::endl;
exit(EXIT_FAILURE);
}
std::cout << "Monitor listening on *:" << settings::MONITORPORT << std::endl;
REGISTER_SHARD_TIMER(tick, settings::MONITORINTERVAL);
@@ -117,6 +127,8 @@ void Monitor::start(void *unused) {
if (SOCKETERROR(sock))
continue;
setSockNonblocking(listener, sock);
std::cout << "[INFO] New monitor connection from " << inet_ntoa(address.sin_addr) << std::endl;
{