xrootd
XrdClientMessage.hh
Go to the documentation of this file.
00001 #ifndef XRC_MESSAGE_H
00002 #define XRC_MESSAGE_H
00003 /******************************************************************************/
00004 /*                                                                            */
00005 /*                 X r d C l i e n t M e s s a g e . 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 // A message coming from a physical connection. I.e. a server response  //
00036 //  or some kind of error                                               //
00037 //                                                                      //
00039 
00040 #include "XProtocol/XProtocol.hh"
00041 #include "XrdSys/XrdSysPthread.hh"
00042 
00043 #ifndef WIN32
00044 #include <netinet/in.h>
00045 #endif
00046 
00047 class XrdClientPhyConnection;
00048 
00049 class XrdClientMessage {
00050 
00051 private:
00052    bool           fAllocated;
00053    void           *fData;
00054    bool           fMarshalled;
00055    short          fStatusCode;
00056    XrdSysRecMutex fMultireadMutex;
00057 
00058 public:
00059 
00060    static kXR_unt16       CharStreamid2Int(kXR_char *charstreamid);
00061    static void            Int2CharStreamid(kXR_char *charstreamid, short intstreamid);
00062 
00063    enum EXrdMSCStatus {             // Some status codes useful
00064       kXrdMSC_ok               = 0,
00065       kXrdMSC_readerr          = 1,
00066       kXrdMSC_writeerr         = 2,
00067       kXrdMSC_timeout          = 3
00068    };
00069 
00070    ServerResponseHeader fHdr;
00071 
00072    XrdClientMessage(ServerResponseHeader header);
00073    XrdClientMessage();
00074 
00075    ~XrdClientMessage();
00076 
00077    bool               CreateData();
00078 
00079    inline int         DataLen() { return fHdr.dlen; }
00080 
00081    void              *DonateData();
00082    inline void       *GetData() {return fData;}
00083    inline int         GetStatusCode() { return fStatusCode; }
00084 
00085    inline int         HeaderStatus() { return fHdr.status; }
00086 
00087    inline kXR_unt16   HeaderSID() { return CharStreamid2Int(fHdr.streamid); }
00088 
00089    bool               IsAttn() { return (HeaderStatus() == kXR_attn); }
00090 
00091    inline bool        IsError() { return (fStatusCode != kXrdMSC_ok); };
00092 
00093    inline bool        IsMarshalled() { return fMarshalled; }
00094    void               Marshall();
00095    inline bool        MatchStreamid(short sid) { return (HeaderSID() == sid);}
00096    int                ReadRaw(XrdClientPhyConnection *phy);
00097    inline void        SetHeaderStatus(kXR_unt16 sts) { fHdr.status = sts; }
00098    inline void        SetMarshalled(bool m) { fMarshalled = m; }
00099    inline void        SetStatusCode(kXR_unt16 status) { fStatusCode = status; }
00100    void               Unmarshall();
00101 
00102 };
00103 #endif