/* * The Unix Channel * * by Michel Beaudouin-Lafon * * Copyright 1990-1993 * Laboratoire de Recherche en Informatique (LRI) * * Reliable datagrams - to be updated * * $Id$ * $CurLog$ */ #ifndef _DGRAM_H_ #define _DGRAM_H_ #include "global.h" #include "Datagram.h" #include "ccu/IdTable.h" #include "ccu/List.h" #include "ccu/Timer.h" class UchDGRAM; class UchMessage; class UchDGRAM_TIMER : public CcuBaseTimer { protected: UchDGRAM& dgram; void Handle (Millisecond); public: UchDGRAM_TIMER (UchDGRAM&); ~UchDGRAM_TIMER (); }; class PENDING; class UchDGRAM : public UchDatagram { protected: CcuIdTableOf pending; // pending messages sword npending; // number of pending messages short retry; // retry times CcuListOf input; // input messages sword ninput; // number of input messages pUchAddress fromAddr; // address of last acknowledged message lword outId; // id of message sent UchDGRAM_TIMER timer; // timer to resend Millisecond timeout; // timeout for timer short locked; bool resend; bool sync; void Init (); int GetInput (int); bool CheckInput (); bool WaitInput (); void SendAck (lword, UchAddress&); void Expired (); UchMsgBuffer* PrepareToSend (UchAddress&, int retries); int SendBuffer (UchMsgBuffer&, UchAddress&); void RemovePending (lword); bool Wait (lword); void Lock () { locked++; } void Unlock () { if (--locked == 0 && resend) Resend (); } public: UchDGRAM (); UchDGRAM (UchAddress*, UchAddress*); ~UchDGRAM (); int Send (byte*, int, UchAddress&, bool = false, int retries = 0); int Receive (byte*, int); int Reply (byte*, int, bool = false, int retries = 0); int Send (UchMsgBuffer&, UchAddress&, bool = false, bool = false, int retries = 0); int Receive (UchMsgBuffer&); int Reply (UchMsgBuffer&, bool = false, bool = false, int retries = 0); bool Send (UchMessage&, UchAddress&, bool = false, int retries = 0); bool Receive (UchMessage* msg); bool Reply (UchMessage&, bool = false, int retries = 0); virtual bool DiscardNotify (UchMsgBuffer&, UchAddress&); int NumPending () { return npending; } int NumInput () { return ninput; } void SetRetry (short r) { retry = r; } void SetRetryTime (Millisecond); void SetSync (bool s) { sync = s; if (s) Drain (); } void Resend (); void Drain (); virtual bool NewMessage (UchMsgBuffer&); void HandleRead (); bool HandleSelect (); friend class UchDGRAM_TIMER; }; #endif /* _DGRAM_H_ */