Server can handle multiple dropped clients at once
This commit is contained in:
+18
-8
@@ -28,6 +28,7 @@
|
||||
#include <stdexcept>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
@@ -161,9 +162,16 @@ void ServerApplication::Init(int argc, char* argv[]) {
|
||||
}
|
||||
|
||||
void ServerApplication::Proc() {
|
||||
//network buffer
|
||||
SerialPacket* packetBuffer = reinterpret_cast<SerialPacket*>(new char[MAX_PACKET_SIZE]);
|
||||
memset(packetBuffer, 0, MAX_PACKET_SIZE); //zero the buffer
|
||||
|
||||
//time system
|
||||
typedef std::chrono::steady_clock Clock;
|
||||
|
||||
Clock::time_point simTime = Clock::now();
|
||||
Clock::time_point realTime;
|
||||
|
||||
while(running) {
|
||||
//suck in the waiting packets & process them
|
||||
while(network.Receive(packetBuffer)) {
|
||||
@@ -173,18 +181,20 @@ void ServerApplication::Proc() {
|
||||
catch(std::exception& e) {
|
||||
std::cerr << "HandlePacket Error: " << e.what() << std::endl;
|
||||
}
|
||||
memset(packetBuffer, 0, MAX_PACKET_SIZE); //reset the buffer
|
||||
//reset the buffer
|
||||
memset(packetBuffer, 0, MAX_PACKET_SIZE);
|
||||
}
|
||||
//update the internals
|
||||
//...
|
||||
|
||||
//Check connections
|
||||
int disconnected = clientMgr.CheckConnections();
|
||||
if (disconnected != -1) {
|
||||
FullClientUnload(disconnected);
|
||||
std::cerr << "Client dropped: " << disconnected << std::endl;
|
||||
//Check client connections
|
||||
std::list<int> disconnections = clientMgr.CheckConnections();
|
||||
for(auto const& it : disconnections) {
|
||||
FullClientUnload(it);
|
||||
std::cerr << "Client dropped: " << it << std::endl;
|
||||
}
|
||||
|
||||
//"tick" the internals
|
||||
//...
|
||||
|
||||
//give the machine a break
|
||||
SDL_Delay(10);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user