xrootd
XrdProtocol.hh
Go to the documentation of this file.
00001 #ifndef __XrdProtocol_H__
00002 #define __XrdProtocol_H__
00003 /******************************************************************************/
00004 /*                                                                            */
00005 /*                        X r d P r o t o c o l . h h                         */
00006 /*                                                                            */
00007 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University  */
00008 /*       All Rights Reserved. See XrdInfo.cc for complete License Terms       */
00009 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00010 /*              DE-AC03-76-SFO0515 with the Department of Energy              */
00011 /******************************************************************************/
00012 
00013 #include "Xrd/XrdJob.hh"
00014  
00015 /******************************************************************************/
00016 /*                    X r d P r o t o c o l _ C o n f i g                     */
00017 /******************************************************************************/
00018   
00019 // The following class is passed to the XrdgetProtocol() and XrdgetProtocolPort()
00020 // functions to properly configure the protocol. This object is not stable and 
00021 // the protocol must copy out any values it desires to keep. It may copy the 
00022 // whole object using the supplied copy constructor.
00023 
00024 class XrdSysError;
00025 class XrdOucTrace;
00026 class XrdBuffManager;
00027 class XrdInet;
00028 class XrdScheduler;
00029 class XrdStats;
00030 
00031 struct sockaddr;
00032 
00033 class XrdProtocol_Config
00034 {
00035 public:
00036 
00037 // The following pointers may be copied; they are stable.
00038 //
00039 XrdSysError    *eDest;       // Stable -> Error Message/Logging Handler
00040 XrdInet        *NetTCP;      // Stable -> Network Object    (@ XrdgetProtocol)
00041 XrdBuffManager *BPool;       // Stable -> Buffer Pool Manager
00042 XrdScheduler   *Sched;       // Stable -> System Scheduler
00043 XrdStats       *Stats;       // Stable -> System Statistics (@ XrdgetProtocol)
00044 void           *Reserved;    // Stable -> Previously, the thread manager
00045 XrdOucTrace    *Trace;       // Stable -> Trace Information
00046 
00047 // The following information must be duplicated; it is unstable.
00048 //
00049 char            *ConfigFN;     // -> Configuration file
00050 int              Format;       // Binary format of this server
00051 int              Port;         // Port number
00052 int              WSize;        // Window size for Port
00053 const char      *AdmPath;      // Admin path
00054 int              AdmMode;      // Admin path mode
00055 const char      *myInst;       // Instance name
00056 const char      *myName;       // Host name
00057 const char      *myProg;       // Program name
00058 struct sockaddr *myAddr;       // Host address
00059 int              ConnMax;      // Max connections
00060 int              readWait;     // Max milliseconds to wait for data
00061 int              idleWait;     // Max milliseconds connection may be idle
00062 int              argc;         // Number of arguments
00063 char           **argv;         // Argument array (prescreened)
00064 char             DebugON;      // True if started with -d option
00065 int              WANPort;      // Port prefered for WAN connections (0 if none)
00066 int              WANWSize;     // Window size for the WANPort
00067 int              hailWait;     // Max milliseconds to wait for data after accept
00068 
00069                  XrdProtocol_Config(XrdProtocol_Config &rhs);
00070                  XrdProtocol_Config() {}
00071                 ~XrdProtocol_Config() {}
00072 };
00073 
00074 /******************************************************************************/
00075 /*                           X r d P r o t o c o l                            */
00076 /******************************************************************************/
00077 
00078 // This class is used by the Link object to process the input stream on a link.
00079 // At least one protocol object exists per Link object. Specific protocols are 
00080 // derived from this pure abstract class since a link can use one of several 
00081 // protocols. Indeed, startup and shutdown are handled by specialized protocols.
00082 
00083 // System configuration obtains an instance of a protocol by calling
00084 // XrdgetProtocol(), which must exist in the shared library.
00085 // This instance is used as the base pointer for Alloc(), Configure(), and
00086 // Match(). Unfortuantely, they cannot be static given the silly C++ rules.
00087 
00088 class XrdLink;
00089   
00090 class XrdProtocol : public XrdJob
00091 {
00092 public:
00093 
00094 // Match()     is invoked when a new link is created and we are trying
00095 //             to determine if this protocol can handle the link. It must
00096 //             return a protocol object if it can and NULL (0), otherwise.
00097 //
00098 virtual XrdProtocol  *Match(XrdLink *lp) = 0;
00099 
00100 // Process()   is invoked when a link has data waiting to be read
00101 //
00102 virtual int           Process(XrdLink *lp) = 0;
00103 
00104 // Recycle()   is invoked when this object is no longer needed. The method is
00105 //             passed the number of seconds the protocol was connected to the
00106 //             link and the reason for the disconnection, if any.
00107 //
00108 virtual void          Recycle(XrdLink *lp=0,int consec=0,const char *reason=0)=0;
00109 
00110 // Stats()     is invoked when we need statistics about all instances of the
00111 //             protocol. If a buffer is supplied, it must return a null 
00112 //             terminated string in the supplied buffer and the return value
00113 //             is the number of bytes placed in the buffer defined by C99 for 
00114 //             snprintf(). If no buffer is supplied, the method should return
00115 //             the maximum number of characters that could have been returned.
00116 //             Regardless of the buffer value, if do_sync is true, the method
00117 //             should include any local statistics in the global data (if any)
00118 //             prior to performing any action.
00119 //
00120 virtual int           Stats(char *buff, int blen, int do_sync=0) = 0;
00121 
00122             XrdProtocol(const char *jname): XrdJob(jname) {}
00123 virtual    ~XrdProtocol() {}
00124 };
00125 
00126 /******************************************************************************/
00127 /*                        X r d g e t P r o t o c o l                         */
00128 /******************************************************************************/
00129   
00130 /* This extern "C" function must be defined in the shared library plug-in
00131    implementing your protocol. It is called to obtain an instance of your
00132    protocol. This allows protocols to live outside of the protocol driver
00133    (i.e., to be loaded at run-time). The call is made after the call to
00134    XrdgetProtocolPort() to determine the port to be used (see below) which
00135    allows e network object (NetTCP) to be proerly defined and it's pointer
00136    is passed in the XrdProtocol_Config object for your use.
00137 
00138    Required return values:
00139    Success: Pointer to XrdProtocol object.
00140    Failure: Null pointer (i.e. 0) which causes the program to exit.
00141 
00142 extern "C"  // This is in a comment!
00143 {
00144        XrdProtocol *XrdgetProtocol(const char *protocol_name, char *parms,
00145                                    XrdProtocol_Config *pi) {....}
00146 }
00147 */
00148   
00149 /******************************************************************************/
00150 /*                    X r d g e t P r o t o c o l P o r t                     */
00151 /******************************************************************************/
00152   
00153 /* This extern "C" function must be defined for statically linked protocols
00154    but is optional for protocols defined as a shared library plug-in if the
00155    rules determining which port number to use is sufficient for your protocol.
00156    The function is called to obtain the actual port number to be used by the
00157    the protocol. The default port number is noted in XrdProtocol_Config Port.
00158    Initially, it has one of the fllowing values:
00159    <0 -> No port was specified.
00160    =0 -> An erbitrary port will be assigned.
00161    >0 -> This port number was specified.
00162 
00163    XrdgetProtoclPort() must return:
00164    <0 -> Failure is indicated and we terminate
00165    =0 -> Use an arbitrary port (even if this equals Port)
00166    >0 -> The returned port number must be used (even if it equals Port)
00167 
00168    When we finally call XrdgetProtocol(), the actual port number is indicated
00169    in Port and the network object is defined in NetTCP and bound to the port.
00170 
00171    Final Caveats: 1.  The network object (NetTCP) is not defined until
00172                       XrdgetProtocol() is called.
00173 
00174                   2.  The statistics object (Stats) is not defined until
00175                       XrdgetProtocol() is called.
00176 
00177                   3.  When the protocol is loaded from a shared library, you need
00178                       need not define XrdgetProtocolPort() if the standard port
00179                       determination scheme is sufficient.
00180 
00181 extern "C"  // This is in a comment!
00182 {
00183        int XrdgetProtocolPort(const char *protocol_name, char *parms,
00184                               XrdProtocol_Config *pi) {....}
00185 }
00186 */
00187 #endif