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