|
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_UTILS_HH__ 00020 #define __XRD_CL_UTILS_HH__ 00021 00022 #include <string> 00023 #include <vector> 00024 #include <netinet/in.h> 00025 #include "XrdCl/XrdClStatus.hh" 00026 #include "XrdCl/XrdClLog.hh" 00027 #include "XrdCl/XrdClURL.hh" 00028 #include "XrdCl/XrdClXRootDResponses.hh" 00029 00030 #include <sys/time.h> 00031 00032 namespace XrdCl 00033 { 00034 //---------------------------------------------------------------------------- 00036 //---------------------------------------------------------------------------- 00037 class Utils 00038 { 00039 public: 00040 //------------------------------------------------------------------------ 00042 //------------------------------------------------------------------------ 00043 template<class Container> 00044 static void splitString( Container &result, 00045 const std::string &input, 00046 const std::string &delimiter ) 00047 { 00048 size_t start = 0; 00049 size_t end = 0; 00050 size_t length = 0; 00051 00052 do 00053 { 00054 end = input.find( delimiter, start ); 00055 00056 if( end != std::string::npos ) 00057 length = end - start; 00058 else 00059 length = input.length() - start; 00060 00061 if( length ) 00062 result.push_back( input.substr( start, length ) ); 00063 00064 start = end + delimiter.size(); 00065 } 00066 while( end != std::string::npos ); 00067 } 00068 00069 //------------------------------------------------------------------------ 00071 //------------------------------------------------------------------------ 00072 static Status GetHostAddresses( std::vector<sockaddr_in> &addresses, 00073 const URL &url); 00074 00075 //------------------------------------------------------------------------ 00077 //------------------------------------------------------------------------ 00078 static void LogHostAddresses( Log *log, 00079 uint64_t type, 00080 const std::string &hostId, 00081 std::vector<sockaddr_in> &addresses ); 00082 00083 //------------------------------------------------------------------------ 00085 //------------------------------------------------------------------------ 00086 static std::string TimeToString( time_t timestamp ); 00087 00088 //------------------------------------------------------------------------ 00090 //------------------------------------------------------------------------ 00091 static uint64_t GetElapsedMicroSecs( timeval start, timeval end ); 00092 00093 //------------------------------------------------------------------------ 00095 //------------------------------------------------------------------------ 00096 static XRootDStatus GetRemoteCheckSum( std::string &checkSum, 00097 const std::string &checkSumType, 00098 const std::string &server, 00099 const std::string &path ); 00100 00101 //------------------------------------------------------------------------ 00103 //------------------------------------------------------------------------ 00104 static XRootDStatus GetLocalCheckSum( std::string &checkSum, 00105 const std::string &checkSumType, 00106 const std::string &path ); 00107 00108 //------------------------------------------------------------------------ 00110 //------------------------------------------------------------------------ 00111 static std::string BytesToString( uint64_t bytes ); 00112 00113 //------------------------------------------------------------------------ 00115 //------------------------------------------------------------------------ 00116 static XRootDStatus CheckTPC( const std::string &server ); 00117 }; 00118 00119 //---------------------------------------------------------------------------- 00121 //---------------------------------------------------------------------------- 00122 class ScopedDescriptor 00123 { 00124 public: 00125 //------------------------------------------------------------------------ 00127 //------------------------------------------------------------------------ 00128 ScopedDescriptor( int descriptor ): pDescriptor( descriptor ) {} 00129 00130 //------------------------------------------------------------------------ 00132 //------------------------------------------------------------------------ 00133 ~ScopedDescriptor() { if( pDescriptor >= 0 ) close( pDescriptor ); } 00134 00135 //------------------------------------------------------------------------ 00137 //------------------------------------------------------------------------ 00138 int Release() 00139 { 00140 int desc = pDescriptor; 00141 pDescriptor = -1; 00142 return desc; 00143 } 00144 00145 //------------------------------------------------------------------------ 00147 //------------------------------------------------------------------------ 00148 int GetDescriptor() 00149 { 00150 return pDescriptor; 00151 } 00152 00153 private: 00154 int pDescriptor; 00155 }; 00156 } 00157 00158 #endif // __XRD_CL_UTILS_HH__
1.7.6.1