server code / add dedicated thread to close/join terminated connection threads

This commit is contained in:
Benjamin Sergeant
2019-05-13 12:20:03 -07:00
parent 849a41293f
commit 841cfe37dd
2 changed files with 56 additions and 26 deletions

View File

@ -74,6 +74,12 @@ namespace ix
// background thread to wait for incoming connections
std::atomic<bool> _stop;
std::thread _thread;
void run();
// background thread to cleanup (join) terminated threads
std::atomic<bool> _stopGc;
std::thread _gcThread;
void runGC();
// the list of (connectionState, threads) for each connections
ConnectionThreads _connectionsThreads;
@ -87,13 +93,12 @@ namespace ix
// the factory to create ConnectionState objects
ConnectionStateFactory _connectionStateFactory;
// Methods
void run();
virtual void handleConnection(int fd,
std::shared_ptr<ConnectionState> connectionState) = 0;
virtual size_t getConnectedClientsCount() = 0;
// Returns true if all connection threads are joined
bool closeTerminatedThreads();
void closeTerminatedThreads();
size_t getConnectionsThreadsCount();
};
}