|
xrootd
|
00001 //------------------------------------------------------------------------------ 00002 // Copyright (c) 2011-2012 by European Organization for Nuclear Research (CERN) 00003 // Author: Lukasz Janyst <ljanyst@cern.ch> 00004 //------------------------------------------------------------------------------ 00005 // XRootD is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU Lesser General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // XRootD is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU Lesser General Public License 00016 // along with XRootD. If not, see <http://www.gnu.org/licenses/>. 00017 //------------------------------------------------------------------------------ 00018 00019 #ifndef __XRD_CL_XROOTD_MSG_HANDLER_HH__ 00020 #define __XRD_CL_XROOTD_MSG_HANDLER_HH__ 00021 00022 #include "XrdCl/XrdClPostMasterInterfaces.hh" 00023 #include "XrdCl/XrdClXRootDResponses.hh" 00024 #include "XrdCl/XrdClDefaultEnv.hh" 00025 #include "XrdCl/XrdClMessage.hh" 00026 #include "XProtocol/XProtocol.hh" 00027 00028 namespace XrdCl 00029 { 00030 class PostMaster; 00031 class SIDManager; 00032 class URL; 00033 00034 //---------------------------------------------------------------------------- 00036 //---------------------------------------------------------------------------- 00037 class XRootDMsgHandler: public IncomingMsgHandler, 00038 public OutgoingMsgHandler 00039 { 00040 public: 00041 //------------------------------------------------------------------------ 00050 //------------------------------------------------------------------------ 00051 XRootDMsgHandler( Message *msg, 00052 ResponseHandler *respHandler, 00053 const URL *url, 00054 SIDManager *sidMgr ): 00055 pRequest( msg ), 00056 pResponse( 0 ), 00057 pResponseHandler( respHandler ), 00058 pUrl( *url ), 00059 pSidMgr( sidMgr ), 00060 pExpiration( 0 ), 00061 pRedirectAsAnswer( false ), 00062 pHosts( 0 ), 00063 pHasLoadBalancer( false ), 00064 pHasSessionId( false ), 00065 pChunkList( 0 ), 00066 pRedirectCounter( 0 ), 00067 00068 pAsyncOffset( 0 ), 00069 pAsyncReadSize( 0 ), 00070 pAsyncReadBuffer( 0 ), 00071 pAsyncMsgSize( 0 ), 00072 00073 pReadRawStarted( false ), 00074 pReadRawCurrentOffset( 0 ), 00075 00076 pReadVRawMsgOffset( 0 ), 00077 pReadVRawChunkHeaderDone( false ), 00078 pReadVRawChunkHeaderStarted( false ), 00079 pReadVRawSizeError( false ), 00080 pReadVRawChunkIndex( -1 ), 00081 pReadVRawMsgDiscard( false ), 00082 00083 pOtherRawStarted( false ) 00084 { 00085 pPostMaster = DefaultEnv::GetPostMaster(); 00086 if( msg->GetSessionId() ) 00087 pHasSessionId = true; 00088 memset( &pReadVRawChunkHeader, 0, sizeof( readahead_list ) ); 00089 } 00090 00091 //------------------------------------------------------------------------ 00093 //------------------------------------------------------------------------ 00094 ~XRootDMsgHandler() 00095 { 00096 if( !pHasSessionId ) 00097 delete pRequest; 00098 delete pResponse; 00099 std::vector<Message *>::iterator it; 00100 for( it = pPartialResps.begin(); it != pPartialResps.end(); ++it ) 00101 delete *it; 00102 } 00103 00104 //------------------------------------------------------------------------ 00110 //------------------------------------------------------------------------ 00111 virtual uint16_t Examine( Message *msg ); 00112 00113 //------------------------------------------------------------------------ 00117 //------------------------------------------------------------------------ 00118 virtual void Process( Message *msg ); 00119 00120 //------------------------------------------------------------------------ 00130 //------------------------------------------------------------------------ 00131 virtual Status ReadMessageBody( Message *msg, 00132 int socket, 00133 uint32_t &bytesRead ); 00134 00135 //------------------------------------------------------------------------ 00141 //------------------------------------------------------------------------ 00142 virtual uint8_t OnStreamEvent( StreamEvent event, 00143 uint16_t streamNum, 00144 Status status ); 00145 00146 //------------------------------------------------------------------------ 00148 //------------------------------------------------------------------------ 00149 virtual void OnStatusReady( const Message *message, 00150 Status status ); 00151 00152 //------------------------------------------------------------------------ 00154 //------------------------------------------------------------------------ 00155 virtual bool IsRaw() const; 00156 00157 //------------------------------------------------------------------------ 00166 //------------------------------------------------------------------------ 00167 virtual Status WriteMessageBody( int socket, 00168 uint32_t &bytesRead ); 00169 00170 //------------------------------------------------------------------------ 00174 //------------------------------------------------------------------------ 00175 void WaitDone( time_t now ); 00176 00177 //------------------------------------------------------------------------ 00179 //------------------------------------------------------------------------ 00180 void SetExpiration( time_t expiration ) 00181 { 00182 pExpiration = expiration; 00183 } 00184 00185 //------------------------------------------------------------------------ 00188 //------------------------------------------------------------------------ 00189 void SetRedirectAsAnswer( bool redirectAsAnswer ) 00190 { 00191 pRedirectAsAnswer = redirectAsAnswer; 00192 } 00193 00194 //------------------------------------------------------------------------ 00196 //------------------------------------------------------------------------ 00197 const Message *GetRequest() const 00198 { 00199 return pRequest; 00200 } 00201 00202 //------------------------------------------------------------------------ 00204 //------------------------------------------------------------------------ 00205 void SetLoadBalancer( const HostInfo &loadBalancer ) 00206 { 00207 if( !loadBalancer.url.IsValid() ) 00208 return; 00209 pLoadBalancer = loadBalancer; 00210 pHasLoadBalancer = true; 00211 } 00212 00213 //------------------------------------------------------------------------ 00215 //------------------------------------------------------------------------ 00216 void SetHostList( HostList *hostList ) 00217 { 00218 delete pHosts; 00219 pHosts = hostList; 00220 } 00221 00222 //------------------------------------------------------------------------ 00224 //------------------------------------------------------------------------ 00225 void SetChunkList( ChunkList *chunkList ) 00226 { 00227 pChunkList = chunkList; 00228 if( chunkList ) 00229 pChunkStatus.resize( chunkList->size() ); 00230 else 00231 pChunkStatus.clear(); 00232 } 00233 00234 //------------------------------------------------------------------------ 00236 //------------------------------------------------------------------------ 00237 void SetRedirectCounter( uint16_t redirectCounter ) 00238 { 00239 pRedirectCounter = redirectCounter; 00240 } 00241 00242 private: 00243 //------------------------------------------------------------------------ 00245 //------------------------------------------------------------------------ 00246 Status ReadRawRead( Message *msg, 00247 int socket, 00248 uint32_t &bytesRead ); 00249 00250 //------------------------------------------------------------------------ 00252 //------------------------------------------------------------------------ 00253 Status ReadRawReadV( Message *msg, 00254 int socket, 00255 uint32_t &bytesRead ); 00256 00257 //------------------------------------------------------------------------ 00259 //------------------------------------------------------------------------ 00260 Status ReadRawOther( Message *msg, 00261 int socket, 00262 uint32_t &bytesRead ); 00263 00264 //------------------------------------------------------------------------ 00267 //------------------------------------------------------------------------ 00268 Status ReadAsync( int socket, uint32_t &btesRead ); 00269 00270 //------------------------------------------------------------------------ 00272 //------------------------------------------------------------------------ 00273 void HandleError( Status status, Message *msg = 0 ); 00274 00275 //------------------------------------------------------------------------ 00277 //------------------------------------------------------------------------ 00278 Status RetryAtServer( const URL &url ); 00279 00280 //------------------------------------------------------------------------ 00282 //------------------------------------------------------------------------ 00283 void HandleResponse(); 00284 00285 //------------------------------------------------------------------------ 00287 //------------------------------------------------------------------------ 00288 XRootDStatus *ProcessStatus(); 00289 00290 //------------------------------------------------------------------------ 00293 //------------------------------------------------------------------------ 00294 Status ParseResponse( AnyObject *&response ); 00295 00296 //------------------------------------------------------------------------ 00299 //------------------------------------------------------------------------ 00300 Status RewriteRequestRedirect( const URL::ParamsMap &newCgi ); 00301 00302 //------------------------------------------------------------------------ 00304 //------------------------------------------------------------------------ 00305 Status RewriteRequestWait(); 00306 00307 //------------------------------------------------------------------------ 00309 //------------------------------------------------------------------------ 00310 Status PostProcessReadV( VectorReadInfo *vReadInfo ); 00311 00312 //------------------------------------------------------------------------ 00314 //------------------------------------------------------------------------ 00315 Status UnPackReadVResponse( Message *msg ); 00316 00317 //------------------------------------------------------------------------ 00319 //------------------------------------------------------------------------ 00320 void UpdateTriedCGI(); 00321 00322 //------------------------------------------------------------------------ 00324 //------------------------------------------------------------------------ 00325 void SwitchOnRefreshFlag(); 00326 00327 //------------------------------------------------------------------------ 00328 // Helper struct for async reading of chunks 00329 //------------------------------------------------------------------------ 00330 struct ChunkStatus 00331 { 00332 ChunkStatus(): sizeError( false ), done( false ) {} 00333 bool sizeError; 00334 bool done; 00335 }; 00336 00337 Message *pRequest; 00338 Message *pResponse; 00339 std::vector<Message *> pPartialResps; 00340 ResponseHandler *pResponseHandler; 00341 URL pUrl; 00342 PostMaster *pPostMaster; 00343 SIDManager *pSidMgr; 00344 Status pStatus; 00345 time_t pExpiration; 00346 bool pRedirectAsAnswer; 00347 HostList *pHosts; 00348 bool pHasLoadBalancer; 00349 HostInfo pLoadBalancer; 00350 bool pHasSessionId; 00351 std::string pRedirectCgi; 00352 ChunkList *pChunkList; 00353 std::vector<ChunkStatus> pChunkStatus; 00354 uint16_t pRedirectCounter; 00355 00356 uint32_t pAsyncOffset; 00357 uint32_t pAsyncReadSize; 00358 char* pAsyncReadBuffer; 00359 uint32_t pAsyncMsgSize; 00360 00361 bool pReadRawStarted; 00362 uint32_t pReadRawCurrentOffset; 00363 00364 uint32_t pReadVRawMsgOffset; 00365 bool pReadVRawChunkHeaderDone; 00366 bool pReadVRawChunkHeaderStarted; 00367 bool pReadVRawSizeError; 00368 int32_t pReadVRawChunkIndex; 00369 readahead_list pReadVRawChunkHeader; 00370 bool pReadVRawMsgDiscard; 00371 00372 bool pOtherRawStarted; 00373 }; 00374 } 00375 00376 #endif // __XRD_CL_XROOTD_MSG_HANDLER_HH__
1.7.6.1