Vault
4.1
|
00001 /* 00002 Copyright c1997-2014 Trygve Isaacson. All rights reserved. 00003 This file is part of the Code Vault version 4.1 00004 http://www.bombaydigital.com/ 00005 License: MIT. See LICENSE.md in the Vault top level directory. 00006 */ 00007 00008 #ifndef vmessageoutputthread_h 00009 #define vmessageoutputthread_h 00010 00013 #include "vsocketthread.h" 00014 #include "vsocketstream.h" 00015 #include "vbinaryiostream.h" 00016 #include "vmessage.h" 00017 #include "vmessagequeue.h" 00018 #include "vclientsession.h" 00019 00020 class VServer; 00021 00031 class VMessageOutputThread : public VSocketThread { 00032 public: 00033 00056 VMessageOutputThread(const VString& threadBaseName, VSocket* socket, VListenerThread* ownerThread, VServer* server, VClientSessionPtr session, VMessageInputThread* dependentInputThread, int maxQueueSize = 0, Vs64 maxQueueDataSize = 0, const VDuration& maxQueueGracePeriod = VDuration::ZERO()); 00060 virtual ~VMessageOutputThread(); 00061 00065 virtual void run(); 00066 00071 virtual void stop(); 00072 00078 void attachSession(VClientSessionPtr session); 00079 00093 bool postOutputMessage(VMessagePtr message, bool respectQueueLimits = true); 00094 00100 void releaseAllQueuedMessages(); 00101 00106 int getOutputQueueSize() const; 00114 bool isOutputQueueOverLimit(int& currentQueueSize, Vs64& currentQueueDataSize) const; 00115 00116 private: 00117 00118 VMessageOutputThread(const VMessageOutputThread&); // not copyable 00119 VMessageOutputThread& operator=(const VMessageOutputThread&); // not assignable 00120 00124 void _processNextOutboundMessage(); 00125 00126 VMessageQueue mOutputQueue; 00127 VSocketStream mSocketStream; 00128 VBinaryIOStream mOutputStream; 00129 VServer* mServer; 00130 VClientSessionPtr mSession; 00131 VMessageInputThread* mDependentInputThread; 00132 int mMaxQueueSize; 00133 Vs64 mMaxQueueDataSize; 00134 VDuration mMaxQueueGracePeriod; 00135 VInstant mWhenMaxQueueSizeWarned; 00136 00137 // These are the transient flags we use to enforce and monitor the queue limits. 00138 bool mWasOverLimit; 00139 VInstant mWhenWentOverLimit; 00140 }; 00141 00142 #endif /* vmessageoutputthread_h */