mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2026-03-15 18:40:03 +00:00
Tweak terminate() slightly
* Gave it a default argument, since we never actually care about it, but it needs to have it to conform to the signal handler prototype * Constricted the area locked by activeCrit to only the block that deals with the connections vector, to lower the chance of a future badly placed call to terminate() deadlocking the server instead
This commit is contained in:
@@ -313,13 +313,11 @@ void CNServer::start() {
|
||||
int n = poll(fds.data(), fds.size(), 50);
|
||||
if (SOCKETERROR(n)) {
|
||||
std::cout << "[FATAL] poll() returned error" << std::endl;
|
||||
terminate(0);
|
||||
terminate();
|
||||
}
|
||||
|
||||
oldnfds = fds.size();
|
||||
|
||||
activeCrit.lock();
|
||||
|
||||
for (int i = 0; i < oldnfds && n > 0; i++) {
|
||||
if (fds[i].revents == 0)
|
||||
continue; // nothing in this one; don't decrement n
|
||||
@@ -331,8 +329,7 @@ void CNServer::start() {
|
||||
// any sort of error on the listener
|
||||
if (fds[i].revents & ~POLLIN) {
|
||||
std::cout << "[FATAL] Error on listener socket" << std::endl;
|
||||
activeCrit.unlock(); // must unlock before calling terminate()
|
||||
terminate(0);
|
||||
terminate();
|
||||
}
|
||||
|
||||
SOCKET newConnectionSocket = accept(sock, (struct sockaddr *)&address, (socklen_t*)&addressSize);
|
||||
@@ -355,6 +352,8 @@ void CNServer::start() {
|
||||
// no-op. handled in checkExtraSockets().
|
||||
|
||||
} else {
|
||||
std::lock_guard<std::mutex> lock(activeCrit); // protect operations on connections
|
||||
|
||||
// player sockets
|
||||
if (connections.find(fds[i].fd) == connections.end()) {
|
||||
std::cout << "[WARN] Event on non-existant socket?" << std::endl;
|
||||
@@ -380,7 +379,6 @@ void CNServer::start() {
|
||||
}
|
||||
|
||||
onStep();
|
||||
activeCrit.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user