Check for dead clients while checking for available messages

This commit is contained in:
Kyle Feuz
2015-02-06 11:54:52 -07:00
parent 10727da7f1
commit 3f131d7975

View File

@@ -220,6 +220,16 @@ public class Server implements Runnable {
for (int i = 0; i < clientCount; i++) {
int which = (index + i) % clientCount;
Client client = clients[which];
//Check for valid client
if (!client.active()){
removeIndex(which); //Remove dead client
i--; //Don't skip the next client
//If the client has data make sure lastAvailable
//doesn't end up skipping the next client
which--;
//fall through to allow data from dead clients
//to be retreived.
}
if (client.available() > 0) {
lastAvailable = which;
return client;