00001 #ifndef __RECEIVEWINDOW_H 00002 #define __RECEIVEWINDOW_H 00003 00004 #include <vector> 00005 #include "WindowPosition.h" 00006 00007 class SAR; 00008 00009 class ReceiveWindow : public BasicObject 00010 { 00011 public: 00012 ReceiveWindow(int size, SAR* m_sar); 00013 ~ReceiveWindow(); 00014 00015 int receive(u_char* buffer, int bufferLength); 00016 bool addReceive(TpPacket* packet); 00017 void close(); 00018 00019 virtual void toStream(std::ostream& out); 00020 00021 private: 00022 void removePacket(int seqNum); 00023 int addPacket(TpPacket* packet); 00024 void destroy(); 00025 void setInitialSequenceNumber(int sequenceNumber); 00026 TpPacket* getNext(bool blocking = true); 00027 bool canAdd(TpPacket* packet); 00028 int calcCredits(); 00029 WindowPosition calcMaxAck(); 00030 int reassemble(u_char* buffer, int bufferLength); 00031 void sendAck(); 00032 void dumpDebug(); 00033 00035 WindowPosition m_nextExpected; 00036 00038 WindowPosition m_lastAccepted; 00039 00041 WindowPosition m_lastRead; 00042 00044 //u_char* m_buffer; 00045 vector<u_char> m_excessBuffer; 00046 00048 bool m_reading; 00049 00051 bool m_destroy; 00052 00054 bool m_closed; 00055 00057 //bool m_firstPacket; 00058 00060 bool m_firstAck; 00061 00063 SAR* m_sar; 00064 00066 Condition m_dataSignal; 00067 00069 Condition m_terminate; 00070 00072 int m_size; 00073 00075 Mutex m_slidingWindowLock; 00076 00078 vector<TpPacket*> m_window; 00079 }; 00080 00081 #endif //#define