diff --git a/Makefile b/Makefile index a18b6d2..ca8a1cb 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ LIBS := -lpthread HLSWMASTER_SRC := config.o gameentry.o gamelist.o gameparser.o gamescanner.o \ hlswmaster.o hlswserver.o logging.o modhelper.o modulelist.o \ - multisock.o netpkt.o recvqueue.o socket.o timerservice.o thread.o \ + multisock.o netpkt.o socket.o timerservice.o thread.o \ mod_d3engine.o mod_gamespy1.o mod_gamespy2.o mod_halflife.o \ mod_q3engine.o mod_quake2.o mod_ut.o @@ -31,7 +31,7 @@ dist: clean --exclude hlswmaster-ng/.gitignore \ --exclude hlswmaster-ng/doc \ --exclude hlswmaster-ng/hlswmaster-ng-$(VERSION).tar.gz \ - --exclude hlswmaster-ng/hlswmaster-ng + --exclude hlswmaster-ng/hlswmaster-ng rm hlswmaster-ng clean: diff --git a/gameparser.cpp b/gameparser.cpp index e9fbd91..a7bfde1 100644 --- a/gameparser.cpp +++ b/gameparser.cpp @@ -2,8 +2,8 @@ #include "netpkt.h" #include "gameparser.h" -GameParser::GameParser(RecvQueue& rxQueue, ModuleList& modList, GameList& gameList) -: rxQueue(rxQueue), modList(modList), gameList(gameList) +GameParser::GameParser(GameScanner& scanner, ModuleList& modList, GameList& gameList) +: scanner(scanner), modList(modList), gameList(gameList) { } @@ -14,7 +14,7 @@ int GameParser::execute(void* arg) int ret; while (1) { - pkt = rxQueue.getPkt(); + pkt = scanner.getPkt(); ret = modList.parse(pkt, &gameList); switch (ret) { diff --git a/gameparser.h b/gameparser.h index a519475..31e0958 100644 --- a/gameparser.h +++ b/gameparser.h @@ -3,13 +3,13 @@ #include "thread.h" #include "config.h" -#include "recvqueue.h" +#include "gamescanner.h" #include "modulelist.h" #include "gamelist.h" class GameParser : public Thread { public: - GameParser(RecvQueue& rxQueue, ModuleList& modlist, GameList& gameList); + GameParser(GameScanner& scanner, ModuleList& modlist, GameList& gameList); ~GameParser() {}; int execute(void* arg); @@ -19,7 +19,7 @@ protected: GameParser& operator=(const GameParser& rp); private: - RecvQueue& rxQueue; + GameScanner& scanner; ModuleList& modList; GameList& gameList; }; diff --git a/gamescanner.cpp b/gamescanner.cpp index 57ff083..64e7aac 100644 --- a/gamescanner.cpp +++ b/gamescanner.cpp @@ -5,8 +5,8 @@ #define DEFAULT_SCAN_INTERVAL 30 -GameScanner::GameScanner(Config& conf, ModuleList& modList, RecvQueue& rxQueue) -: modList(modList), rxQueue(rxQueue) +GameScanner::GameScanner(Config& conf, ModuleList& modList) +: modList(modList) { msock = new MultiSock(conf); @@ -16,6 +16,9 @@ GameScanner::GameScanner(Config& conf, ModuleList& modList, RecvQueue& rxQueue) GameScanner::~GameScanner() { + while (!pktList.isEmpty()) + delete pktList.get(); + delete msock; } @@ -23,8 +26,10 @@ int GameScanner::execute(void* arg) { while (1) { NetPkt* pkt = msock->recv(); - if (pkt) - rxQueue.addPkt(pkt); + if (pkt != NULL) { + pktList.add(pkt); + pktCount.post(); + } } return 0; } @@ -33,3 +38,9 @@ void GameScanner::scan() { modList.scan(msock); } + +NetPkt* GameScanner::getPkt() +{ + pktCount.wait(); + return pktList.get(); +} diff --git a/gamescanner.h b/gamescanner.h index 7153fbf..e8145b3 100644 --- a/gamescanner.h +++ b/gamescanner.h @@ -4,19 +4,22 @@ #include "thread.h" #include "config.h" #include "modulelist.h" -#include "recvqueue.h" - #include "timerservice.h" #include "multisock.h" +#include "semaphore.h" +#include "list.h" +#include "netpkt.h" class GameScanner : public Thread { public: - GameScanner(Config& conf, ModuleList& modList, RecvQueue& rxQueue); + GameScanner(Config& conf, ModuleList& modList); ~GameScanner(); int execute(void* arg); void scan(); + NetPkt* getPkt(); + protected: GameScanner(const GameScanner& hs); GameScanner& operator=(const GameScanner& hs); @@ -33,8 +36,10 @@ private: }; ModuleList& modList; - RecvQueue& rxQueue; MultiSock* msock; + + Semaphore pktCount; + LockedList pktList; }; #endif // _SCANNER_H_ diff --git a/hlswmaster.cpp b/hlswmaster.cpp index d287335..d6e8485 100644 --- a/hlswmaster.cpp +++ b/hlswmaster.cpp @@ -5,7 +5,6 @@ #include "logging.h" #include "config.h" -#include "recvqueue.h" #include "modulelist.h" #include "gamelist.h" #include "gamescanner.h" @@ -89,12 +88,11 @@ int main(int argc, char *argv[]) LogSystem::log(LOG_EVERYTIME, "hlswmaster-ng %s startup (pid:%d)", VERSION, getpid()); conf.show(); - RecvQueue rxQueue; ModuleList modList(conf); GameList gameList(conf); - GameScanner scanner(conf, modList, rxQueue); - GameParser parser(rxQueue, modList, gameList); + GameScanner scanner(conf, modList); + GameParser parser(scanner, modList, gameList); HlswServer server(conf, gameList); modList.reg(new ModD3Engine()); diff --git a/recvqueue.cpp b/recvqueue.cpp deleted file mode 100644 index c287616..0000000 --- a/recvqueue.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include "recvqueue.h" - -RecvQueue::~RecvQueue() -{ - while (!pktList.isEmpty()) - delete pktList.get(); -} - -void RecvQueue::addPkt(NetPkt* pkt) -{ - if (pkt != NULL) { - pktList.add(pkt); - pktCount.post(); - } -} - -NetPkt* RecvQueue::getPkt() -{ - pktCount.wait(); - return pktList.get(); -} diff --git a/recvqueue.h b/recvqueue.h deleted file mode 100644 index 3dec760..0000000 --- a/recvqueue.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef _RECVQUEUE_H_ -#define _RECVQUEUE_H_ - -#include "netpkt.h" -#include "semaphore.h" -#include "list.h" - -class RecvQueue { -public: - RecvQueue() {}; - ~RecvQueue(); - - void addPkt(NetPkt* pkt); - NetPkt* getPkt(); - -protected: - RecvQueue(const RecvQueue& rq); - RecvQueue& operator=(const RecvQueue& rq); - -private: - Semaphore pktCount; - LockedList pktList; -}; - -#endif // _RECVQUEUE_H_