00001 ////////////////////////////////////////////////////////////////////////// 00002 // // 00003 // XrdClientInputBuffer // 00004 // // 00005 // Author: Fabrizio Furano (INFN Padova, 2004) // 00006 // Adapted from TXNetFile (root.cern.ch) originally done by // 00007 // Alvise Dorigo, Fabrizio Furano // 00008 // INFN Padova, 2003 // 00009 // // 00010 // Buffer for incoming messages (responses) // 00011 // Handles the waiting (with timeout) for a message to come // 00012 // belonging to a logical streamid // 00013 // Multithread friendly // 00014 // // 00015 ////////////////////////////////////////////////////////////////////////// 00016 00017 // $Id: XrdClientInputBuffer.hh 26376 2008-11-22 11:07:11Z ganis $ 00018 00019 #ifndef XRC_INPUTBUFFER_H 00020 #define XRC_INPUTBUFFER_H 00021 00022 00023 #include "XrdClient/XrdClientMessage.hh" 00024 #include "XrdSys/XrdSysPthread.hh" 00025 #include "XrdSys/XrdSysSemWait.hh" 00026 #include "XrdOuc/XrdOucHash.hh" 00027 #include "XrdClient/XrdClientVector.hh" 00028 00029 using namespace std; 00030 00031 class XrdClientInputBuffer { 00032 00033 private: 00034 00035 XrdClientVector<XrdClientMessage*> fMsgQue; // queue for incoming messages 00036 int fMsgIter; // an iterator on it 00037 00038 XrdSysRecMutex fMutex; // mutex to protect data structures 00039 00040 XrdOucHash<XrdSysSemWait> fSyncobjRepo; 00041 // each streamid counts on a condition 00042 // variable to make the caller wait 00043 // until some data is available 00044 00045 00046 XrdSysSemWait *GetSyncObjOrMakeOne(int streamid); 00047 00048 int MsgForStreamidCnt(int streamid); 00049 00050 public: 00051 XrdClientInputBuffer(); 00052 ~XrdClientInputBuffer(); 00053 00054 inline bool IsMexEmpty() { return (MexSize() == 0); } 00055 inline bool IsSemEmpty() { return (SemSize() == 0); } 00056 inline int MexSize() { 00057 XrdSysMutexHelper mtx(fMutex); 00058 return fMsgQue.GetSize(); 00059 } 00060 int PutMsg(XrdClientMessage *msg); 00061 inline int SemSize() { 00062 XrdSysMutexHelper mtx(fMutex); 00063 return fSyncobjRepo.Num(); 00064 } 00065 00066 int WipeStreamid(int streamid); 00067 00068 XrdClientMessage *GetMsg(int streamid, int secstimeout); 00069 }; 00070 00071 00072 00073 #endif