xrootd
XrdClientInputBuffer.hh
Go to the documentation of this file.
00001 #ifndef XRC_INPUTBUFFER_H
00002 #define XRC_INPUTBUFFER_H
00003 /******************************************************************************/
00004 /*                                                                            */
00005 /*             X r d C l i e n t I n p u t B u f f e r . h h                  */
00006 /*                                                                            */
00007 /* Author: Fabrizio Furano (INFN Padova, 2004)                                */
00008 /* Adapted from TXNetFile (root.cern.ch) originally done by                   */
00009 /*  Alvise Dorigo, Fabrizio Furano                                            */
00010 /*          INFN Padova, 2003                                                 */
00011 /*                                                                            */
00012 /* This file is part of the XRootD software suite.                            */
00013 /*                                                                            */
00014 /* XRootD is free software: you can redistribute it and/or modify it under    */
00015 /* the terms of the GNU Lesser General Public License as published by the     */
00016 /* Free Software Foundation, either version 3 of the License, or (at your     */
00017 /* option) any later version.                                                 */
00018 /*                                                                            */
00019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT      */
00020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      */
00021 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public       */
00022 /* License for more details.                                                  */
00023 /*                                                                            */
00024 /* You should have received a copy of the GNU Lesser General Public License   */
00025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file  */
00026 /* COPYING (GPL license).  If not, see <http://www.gnu.org/licenses/>.        */
00027 /*                                                                            */
00028 /* The copyright holder's institutional names and contributor's names may not */
00029 /* be used to endorse or promote products derived from this software without  */
00030 /* specific prior written permission of the institution or contributor.       */
00031 /******************************************************************************/
00032 
00034 //                                                                      //
00035 // Buffer for incoming messages (responses)                             //
00036 //  Handles the waiting (with timeout) for a message to come            //
00037 //   belonging to a logical streamid                                    //
00038 //  Multithread friendly                                                //
00039 //                                                                      //
00041 
00042 #include "XrdClient/XrdClientMessage.hh"
00043 #include "XrdSys/XrdSysPthread.hh"
00044 #include "XrdSys/XrdSysSemWait.hh"
00045 #include "XrdOuc/XrdOucHash.hh"
00046 #include "XrdClient/XrdClientVector.hh"
00047 
00048 using namespace std;
00049 
00050 class XrdClientInputBuffer {
00051 
00052 private:
00053 
00054    XrdClientVector<XrdClientMessage*> fMsgQue;      // queue for incoming messages
00055    int                                fMsgIter;     // an iterator on it
00056 
00057    XrdSysRecMutex                        fMutex;       // mutex to protect data structures
00058 
00059    XrdOucHash<XrdSysSemWait>          fSyncobjRepo;
00060                                              // each streamid counts on a condition
00061                                              // variable to make the caller wait
00062                                              // until some data is available
00063 
00064 
00065    XrdSysSemWait                      *GetSyncObjOrMakeOne(int streamid);
00066 
00067    int             MsgForStreamidCnt(int streamid);
00068 
00069 public:
00070    XrdClientInputBuffer();
00071   ~XrdClientInputBuffer();
00072 
00073    inline bool     IsMexEmpty() { return (MexSize() == 0); }
00074    inline bool     IsSemEmpty() { return (SemSize() == 0); }
00075    inline int      MexSize() { 
00076                        XrdSysMutexHelper mtx(fMutex);
00077                        return fMsgQue.GetSize();
00078                        }
00079    int             PutMsg(XrdClientMessage *msg);
00080    inline int      SemSize() {
00081                        XrdSysMutexHelper mtx(fMutex);
00082                        return fSyncobjRepo.Num();
00083                        }
00084 
00085    int             WipeStreamid(int streamid);
00086 
00087    XrdClientMessage      *GetMsg(int streamid, int secstimeout);
00088 };
00089 #endif