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