9
3

EQStreamFactory.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef _EQSTREAMFACTORY_H
  17. #define _EQSTREAMFACTORY_H
  18. #include <queue>
  19. #include <map>
  20. #include "../common/EQStream.h"
  21. #include "../common/Condition.h"
  22. #include "../common/opcodemgr.h"
  23. #include "../common/timer.h"
  24. #define STREAM_TIMEOUT 45000 //in ms
  25. class EQStreamFactory {
  26. private:
  27. int sock;
  28. int Port;
  29. bool ReaderRunning;
  30. Mutex MReaderRunning;
  31. bool WriterRunning;
  32. Mutex MWriterRunning;
  33. bool CombinePacketRunning;
  34. Mutex MCombinePacketRunning;
  35. Condition WriterWork;
  36. EQStreamType StreamType;
  37. queue<EQStream *> NewStreams;
  38. Mutex MNewStreams;
  39. map<string,EQStream *> Streams;
  40. Mutex MStreams;
  41. Timer *DecayTimer;
  42. public:
  43. char* listen_ip_address;
  44. void CheckTimeout(bool remove_all = false);
  45. EQStreamFactory(EQStreamType type) { ReaderRunning=false; WriterRunning=false; StreamType=type; }
  46. EQStreamFactory(EQStreamType type, int port);
  47. ~EQStreamFactory(){
  48. safe_delete_array(listen_ip_address);
  49. }
  50. EQStream *Pop();
  51. void Push(EQStream *s);
  52. bool loadPublicKey();
  53. bool Open();
  54. bool Open(unsigned long port) { Port=port; return Open(); }
  55. void Close();
  56. void ReaderLoop();
  57. void WriterLoop();
  58. void CombinePacketLoop();
  59. void Stop() { StopReader(); StopWriter(); StopCombinePacket(); }
  60. void StopReader() { MReaderRunning.lock(); ReaderRunning=false; MReaderRunning.unlock(); }
  61. void StopWriter() { MWriterRunning.lock(); WriterRunning=false; MWriterRunning.unlock(); WriterWork.Signal(); }
  62. void StopCombinePacket() { MCombinePacketRunning.lock(); CombinePacketRunning=false; MCombinePacketRunning.unlock(); }
  63. void SignalWriter() { WriterWork.Signal(); }
  64. };
  65. #endif