XRootD
Loading...
Searching...
No Matches
XrdCl::MessageUtils Class Reference

#include <XrdClMessageUtils.hh>

Collaboration diagram for XrdCl::MessageUtils:

Static Public Member Functions

template<class Request>
static void CreateRequest (Message *&msg, Request *&req, uint32_t payloadSize=0)
 Create a message.
template<typename T>
static Status CreateXAttrBody (Message *msg, const std::vector< T > &vec, const std::string &path="")
static Status CreateXAttrVec (const std::vector< std::string > &attrs, std::vector< char > &nvec)
static Status CreateXAttrVec (const std::vector< xattr_t > &attrs, std::vector< char > &avec)
 Create xattr vector.
static void MergeCGI (URL::ParamsMap &cgi1, const URL::ParamsMap &cgi2, bool replace)
 Merge cgi2 into cgi1.
static void ProcessSendParams (MessageSendParams &sendParams)
 Process sending params.
static Status RedirectMessage (const URL &url, Message *msg, ResponseHandler *handler, MessageSendParams &sendParams, LocalFileHandler *lFileHandler)
 Redirect message.
static void RewriteCGIAndPath (Message *msg, const URL::ParamsMap &newCgi, bool replace, const std::string &newPath, std::string *opathp=nullptr)
 Append cgi to the one already present in the message.
static XRootDStatus SendMessage (const URL &url, Message *msg, ResponseHandler *handler, MessageSendParams &sendParams, LocalFileHandler *lFileHandler)
 Send message.
template<class Type>
static XrdCl::XRootDStatus WaitForResponse (SyncResponseHandler *handler, Type *&response)
 Wait for the response.
static XRootDStatus WaitForStatus (SyncResponseHandler *handler)
 Wait and return the status of the query.

Detailed Description

Definition at line 149 of file XrdClMessageUtils.hh.

Member Function Documentation

◆ CreateRequest()

template<class Request>
void XrdCl::MessageUtils::CreateRequest ( Message *& msg,
Request *& req,
uint32_t payloadSize = 0 )
inlinestatic

Create a message.

Definition at line 198 of file XrdClMessageUtils.hh.

201 {
202 msg = new Message( sizeof(Request) + payloadSize );
203 req = (Request*)msg->GetBuffer();
204 msg->Zero();
205 }

References XrdCl::Buffer::GetBuffer(), and XrdCl::Buffer::Zero().

Referenced by XrdCl::FileStateHandler::Checkpoint(), XrdCl::FileStateHandler::ChkptWrt(), XrdCl::FileStateHandler::ChkptWrtV(), XrdCl::FileSystem::ChMod(), XrdCl::FileStateHandler::Clone(), XrdCl::FileStateHandler::Close(), XrdCl::FileSystem::DirList(), XrdCl::FileStateHandler::Fcntl(), XrdCl::FileSystem::Locate(), XrdCl::FileSystem::MkDir(), XrdCl::FileSystem::Mv(), XrdCl::FileStateHandler::PgReadImpl(), XrdCl::FileStateHandler::PgWriteImpl(), XrdCl::FileSystem::Ping(), XrdCl::FileSystem::Prepare(), XrdCl::FileStateHandler::PreRead(), XrdCl::FileSystem::Protocol(), XrdCl::FileSystem::Query(), XrdCl::FileStateHandler::Read(), XrdCl::FileStateHandler::ReadV(), XrdCl::FileSystem::Rm(), XrdCl::FileSystem::RmDir(), XrdCl::FileStateHandler::Stat(), XrdCl::FileSystem::Stat(), XrdCl::FileSystem::StatVFS(), XrdCl::FileStateHandler::Sync(), XrdCl::FileStateHandler::Truncate(), XrdCl::FileSystem::Truncate(), XrdCl::FileStateHandler::VectorRead(), XrdCl::FileStateHandler::VectorWrite(), XrdCl::FileStateHandler::Visa(), XrdCl::FileStateHandler::Write(), and XrdCl::FileStateHandler::WriteV().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateXAttrBody()

template<typename T>
Status XrdCl::MessageUtils::CreateXAttrBody ( Message * msg,
const std::vector< T > & vec,
const std::string & path = "" )
inlinestatic

Create body of xattr request and set the body size

Parameters
msg: the request
vec: the argument
path: file path

Definition at line 289 of file XrdClMessageUtils.hh.

292 {
293 ClientRequestHdr *hdr = reinterpret_cast<ClientRequestHdr*>( msg->GetBuffer() );
294
295 std::vector<char> xattrvec;
296 Status st = MessageUtils::CreateXAttrVec( vec, xattrvec );
297 if( !st.IsOK() )
298 return st;
299
300 // update body size in the header
301 hdr->dlen = path.size() + 1;
302 hdr->dlen += xattrvec.size();
303
304 // append the body
305 size_t offset = sizeof( ClientRequestHdr );
306 msg->Append( path.c_str(), path.size() + 1, offset );
307 offset += path.size() + 1;
308 msg->Append( xattrvec.data(), xattrvec.size(), offset );
309
310 return Status();
311 }
static Status CreateXAttrVec(const std::vector< xattr_t > &attrs, std::vector< char > &avec)
Create xattr vector.

References XrdCl::Buffer::Append(), CreateXAttrVec(), ClientRequestHdr::dlen, XrdCl::Buffer::GetBuffer(), and XrdCl::Status::IsOK().

Here is the call graph for this function:

◆ CreateXAttrVec() [1/2]

Status XrdCl::MessageUtils::CreateXAttrVec ( const std::vector< std::string > & attrs,
std::vector< char > & nvec )
static

Create xattr name vector vector

Parameters
attrs: extended attribute name list
nvec: vector containing the name vector

Definition at line 458 of file XrdClMessageUtils.cc.

460 {
461 if( attrs.empty() )
462 return Status();
463
464 if( attrs.size() > xfaLimits::kXR_faMaxVars )
465 return Status( stError, errInvalidArgs );
466
467 //----------------------------------------------------------------------
468 // Calculate the name and value vector lengths
469 //----------------------------------------------------------------------
470
471 // 2 bytes for rc + 1 byte for null character at the end
472 static const int name_overhead = 3;
473
474 size_t nlen = 0;
475 for( auto itr = attrs.begin(); itr != attrs.end(); ++itr )
476 nlen += itr->size() + name_overhead;
477
478 if( nlen > xfaLimits::kXR_faMaxNlen )
479 return Status( stError, errInvalidArgs );
480
481 //----------------------------------------------------------------------
482 // Create name vector
483 //----------------------------------------------------------------------
484 nvec.resize( nlen, 0 );
485 char *nptr = nvec.data();
486
487 for( auto itr = attrs.begin(); itr != attrs.end(); ++itr )
488 nptr = ClientFattrRequest::NVecInsert( itr->c_str(), nptr );
489
490 return Status();
491 }
@ kXR_faMaxVars
Definition XProtocol.hh:310
@ kXR_faMaxNlen
Definition XProtocol.hh:311
const uint16_t stError
An error occurred that could potentially be retried.
const uint16_t errInvalidArgs
static char * NVecInsert(const char *name, char *buffer)
Definition XProtocol.cc:176

References XrdCl::errInvalidArgs, kXR_faMaxNlen, kXR_faMaxVars, ClientFattrRequest::NVecInsert(), and XrdCl::stError.

Here is the call graph for this function:

◆ CreateXAttrVec() [2/2]

Status XrdCl::MessageUtils::CreateXAttrVec ( const std::vector< xattr_t > & attrs,
std::vector< char > & avec )
static

Create xattr vector.

Create xattr vector

Parameters
attrs: extended attribute list
avec: vector containing the name vector and the value vector

Definition at line 407 of file XrdClMessageUtils.cc.

409 {
410 if( attrs.empty() )
411 return Status();
412
413 if( attrs.size() > xfaLimits::kXR_faMaxVars )
414 return Status( stError, errInvalidArgs );
415
416 //----------------------------------------------------------------------
417 // Calculate the name and value vector lengths
418 //----------------------------------------------------------------------
419
420 // 2 bytes for rc + 1 byte for null character at the end
421 static const int name_overhead = 3;
422 // 4 bytes for value length
423 static const int value_overhead = 4;
424
425 size_t nlen = 0, vlen = 0;
426 for( auto itr = attrs.begin(); itr != attrs.end(); ++itr )
427 {
428 nlen += std::get<xattr_name>( *itr ).size() + name_overhead;
429 vlen += std::get<xattr_value>( *itr ).size() + value_overhead;
430 }
431
432 if( nlen > xfaLimits::kXR_faMaxNlen )
433 return Status( stError, errInvalidArgs );
434
435 if( vlen > xfaLimits::kXR_faMaxVlen )
436 return Status( stError, errInvalidArgs );
437
438 //----------------------------------------------------------------------
439 // Create name and value vectors
440 //----------------------------------------------------------------------
441 avec.resize( nlen + vlen, 0 );
442 char *nvec = avec.data(), *vvec = avec.data() + nlen;
443
444 for( auto itr = attrs.begin(); itr != attrs.end(); ++itr )
445 {
446 const std::string &name = std::get<xattr_name>( *itr );
447 nvec = ClientFattrRequest::NVecInsert( name.c_str(), nvec );
448 const std::string &value = std::get<xattr_value>( *itr );
449 vvec = ClientFattrRequest::VVecInsert( value.c_str(), vvec );
450 }
451
452 return Status();
453 }
@ kXR_faMaxVlen
Definition XProtocol.hh:312
static char * VVecInsert(const char *value, char *buffer)
Definition XProtocol.cc:192

References XrdCl::errInvalidArgs, kXR_faMaxNlen, kXR_faMaxVars, kXR_faMaxVlen, ClientFattrRequest::NVecInsert(), XrdCl::stError, and ClientFattrRequest::VVecInsert().

Referenced by CreateXAttrBody().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MergeCGI()

void XrdCl::MessageUtils::MergeCGI ( URL::ParamsMap & cgi1,
const URL::ParamsMap & cgi2,
bool replace )
static

Merge cgi2 into cgi1.

Merge cgi2 into cgi1

Parameters
cgi1cgi to be merged into
cgi2cgi to be merged in
replaceindicates whether, in case of a conflict, the new CGI parameter should replace an existing one or be appended to it using a comma

Definition at line 381 of file XrdClMessageUtils.cc.

384 {
385 URL::ParamsMap::const_iterator it;
386 for( it = cgi2.begin(); it != cgi2.end(); ++it )
387 {
388 if( replace || cgi1.find( it->first ) == cgi1.end() )
389 cgi1[it->first] = it->second;
390 else
391 {
392 std::string &v = cgi1[it->first];
393 if( v.empty() )
394 v = it->second;
395 else
396 {
397 v += ',';
398 v += it->second;
399 }
400 }
401 }
402 }

Referenced by XrdCl::FileStateHandler::OnOpen(), XrdCl::FileStateHandler::OnStateRedirection(), RewriteCGIAndPath(), and XrdCl::FileStateHandler::TryOtherServer().

Here is the caller graph for this function:

◆ ProcessSendParams()

void XrdCl::MessageUtils::ProcessSendParams ( MessageSendParams & sendParams)
static

Process sending params.

Definition at line 220 of file XrdClMessageUtils.cc.

221 {
222 //--------------------------------------------------------------------------
223 // Timeout
224 //--------------------------------------------------------------------------
225 Env *env = DefaultEnv::GetEnv();
226 if( sendParams.timeout == 0 )
227 {
228 int requestTimeout = DefaultRequestTimeout;
229 env->GetInt( "RequestTimeout", requestTimeout );
230 sendParams.timeout = requestTimeout;
231 }
232
233 if( sendParams.expires == 0 )
234 sendParams.expires = ::time(0)+sendParams.timeout;
235
236 //--------------------------------------------------------------------------
237 // Redirect limit
238 //--------------------------------------------------------------------------
239 if( sendParams.redirectLimit == 0 )
240 {
241 int redirectLimit = DefaultRedirectLimit;
242 env->GetInt( "RedirectLimit", redirectLimit );
243 sendParams.redirectLimit = redirectLimit;
244 }
245 }
static Env * GetEnv()
Get default client environment.
const int DefaultRedirectLimit
const int DefaultRequestTimeout

References XrdCl::DefaultRedirectLimit, XrdCl::DefaultRequestTimeout, XrdCl::MessageSendParams::expires, XrdCl::DefaultEnv::GetEnv(), XrdCl::Env::GetInt(), XrdCl::MessageSendParams::redirectLimit, and XrdCl::MessageSendParams::timeout.

Referenced by XrdCl::FileStateHandler::Checkpoint(), XrdCl::FileStateHandler::ChkptWrt(), XrdCl::FileStateHandler::ChkptWrtV(), XrdCl::FileSystem::ChMod(), XrdCl::FileStateHandler::Clone(), XrdCl::FileStateHandler::Close(), XrdCl::FileSystem::DirList(), XrdCl::FileStateHandler::Fcntl(), XrdCl::FileSystem::Locate(), XrdCl::FileSystem::MkDir(), XrdCl::FileSystem::Mv(), XrdCl::FileStateHandler::PgReadImpl(), XrdCl::FileStateHandler::PgWriteImpl(), XrdCl::FileSystem::Ping(), XrdCl::FileSystem::Prepare(), XrdCl::FileStateHandler::PreRead(), XrdCl::FileSystem::Protocol(), XrdCl::FileSystem::Query(), XrdCl::FileStateHandler::Read(), XrdCl::FileStateHandler::ReadV(), XrdCl::FileSystem::Rm(), XrdCl::FileSystem::RmDir(), XrdCl::FileStateHandler::Stat(), XrdCl::FileSystem::Stat(), XrdCl::FileSystem::StatVFS(), XrdCl::FileStateHandler::Sync(), XrdCl::FileStateHandler::Truncate(), XrdCl::FileSystem::Truncate(), XrdCl::FileStateHandler::VectorRead(), XrdCl::FileStateHandler::VectorWrite(), XrdCl::FileStateHandler::Visa(), XrdCl::FileStateHandler::Write(), and XrdCl::FileStateHandler::WriteV().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RedirectMessage()

Status XrdCl::MessageUtils::RedirectMessage ( const URL & url,
Message * msg,
ResponseHandler * handler,
MessageSendParams & sendParams,
LocalFileHandler * lFileHandler )
static

Redirect message.

Definition at line 150 of file XrdClMessageUtils.cc.

155 {
156 //--------------------------------------------------------------------------
157 // Register a new virtual redirector
158 //--------------------------------------------------------------------------
159 RedirectorRegistry& registry = RedirectorRegistry::Instance();
160 Status st = registry.Register( url );
161 if( !st.IsOK() )
162 return st;
163
164 //--------------------------------------------------------------------------
165 // Get the stuff needed to send the message
166 //--------------------------------------------------------------------------
167 Log *log = DefaultEnv::GetLog();
168 PostMaster *postMaster = DefaultEnv::GetPostMaster();
169
170 if( !postMaster )
171 return Status( stError, errUninitialized );
172
173 log->Dump( XRootDMsg, "[%s] Redirecting message %s",
174 url.GetHostId().c_str(), msg->GetObfuscatedDescription().c_str() );
175
177
178 //--------------------------------------------------------------------------
179 // Create and set up the message handler
180 //--------------------------------------------------------------------------
181 XRootDMsgHandler *msgHandler;
182 msgHandler = new XRootDMsgHandler( msg, handler, &url, std::shared_ptr<SIDManager>(), lFileHandler );
183 msgHandler->SetExpiration( sendParams.expires );
184 msgHandler->SetRedirectAsAnswer( !sendParams.followRedirects );
185 msgHandler->SetOksofarAsAnswer( sendParams.chunkedResponse );
186 msgHandler->SetChunkList( sendParams.chunkList );
187 msgHandler->SetRedirectCounter( sendParams.redirectLimit );
188 msgHandler->SetFollowMetalink( true );
189
190 HostInfo info( url, true );
192 sendParams.loadBalancer = info;
193 msgHandler->SetLoadBalancer( info );
194
195 HostList *list = 0;
196 list = new HostList();
197 list->push_back( info );
198 msgHandler->SetHostList( list );
199
200 //--------------------------------------------------------------------------
201 // Redirect the message
202 //--------------------------------------------------------------------------
203 st = postMaster->Redirect( url, msg, msgHandler );
204 if( !st.IsOK() )
205 {
207 log->Error( XRootDMsg, "[%s] Unable to send the message %s: %s",
208 url.GetHostId().c_str(), msg->GetObfuscatedDescription().c_str(),
209 st.ToString().c_str() );
210 delete msgHandler;
211 delete list;
212 return st;
213 }
214 return Status();
215 }
#define kXR_isManager
#define kXR_attrMeta
#define kXR_attrVirtRdr
static Log * GetLog()
Get default log.
static PostMaster * GetPostMaster()
Get default post master.
static RedirectorRegistry & Instance()
Returns reference to the single instance.
static XRootDStatus UnMarshallRequest(Message *msg)
static XRootDStatus MarshallRequest(Message *msg)
Marshal the outgoing message.
const uint16_t errUninitialized
const uint64_t XRootDMsg
std::vector< HostInfo > HostList
XrdSysError Log
Definition XrdConfig.cc:113

References XrdCl::MessageSendParams::chunkedResponse, XrdCl::MessageSendParams::chunkList, XrdCl::Log::Dump(), XrdCl::Log::Error(), XrdCl::errUninitialized, XrdCl::MessageSendParams::expires, XrdCl::HostInfo::flags, XrdCl::MessageSendParams::followRedirects, XrdCl::URL::GetHostId(), XrdCl::DefaultEnv::GetLog(), XrdCl::Message::GetObfuscatedDescription(), XrdCl::DefaultEnv::GetPostMaster(), XrdCl::RedirectorRegistry::Instance(), XrdCl::Status::IsOK(), kXR_attrMeta, kXR_attrVirtRdr, kXR_isManager, XrdCl::MessageSendParams::loadBalancer, XrdCl::XRootDTransport::MarshallRequest(), XrdCl::PostMaster::Redirect(), XrdCl::MessageSendParams::redirectLimit, XrdCl::RedirectorRegistry::Register(), XrdCl::XRootDMsgHandler::SetChunkList(), XrdCl::XRootDMsgHandler::SetExpiration(), XrdCl::XRootDMsgHandler::SetFollowMetalink(), XrdCl::XRootDMsgHandler::SetHostList(), XrdCl::XRootDMsgHandler::SetLoadBalancer(), XrdCl::XRootDMsgHandler::SetOksofarAsAnswer(), XrdCl::XRootDMsgHandler::SetRedirectAsAnswer(), XrdCl::XRootDMsgHandler::SetRedirectCounter(), XrdCl::stError, XrdCl::Status::ToString(), XrdCl::XRootDTransport::UnMarshallRequest(), and XrdCl::XRootDMsg.

Here is the call graph for this function:

◆ RewriteCGIAndPath()

void XrdCl::MessageUtils::RewriteCGIAndPath ( Message * msg,
const URL::ParamsMap & newCgi,
bool replace,
const std::string & newPath,
std::string * opathp = nullptr )
static

Append cgi to the one already present in the message.

Rewrite CGI and path if necessary

Parameters
msgmessage concerned
newCgithe new cgi
replaceindicates whether, in case of a conflict, the new CGI parameter should replace an existing one or be appended to it using a comma
newPathwill be used as the new destination path if it is not empty
opathpif not null will be filled with the initial path contained in the message, before it is set to newPath

Definition at line 250 of file XrdClMessageUtils.cc.

255 {
256 ClientRequest *req = (ClientRequest *)msg->GetBuffer();
257 switch( req->header.requestid )
258 {
259 case kXR_chmod:
260 case kXR_mkdir:
261 case kXR_mv:
262 case kXR_open:
263 case kXR_rm:
264 case kXR_rmdir:
265 case kXR_stat:
266 case kXR_truncate:
267 {
268 //----------------------------------------------------------------------
269 // Get the pointer to the appropriate path
270 //----------------------------------------------------------------------
271 char *path = msg->GetBuffer( 24 );
272 size_t length = req->header.dlen;
273 if( req->header.requestid == kXR_mv )
274 {
275 for( int i = 0; i < req->header.dlen; ++i, ++path, --length )
276 if( *path == ' ' )
277 break;
278 ++path;
279 --length;
280 }
281
282 //----------------------------------------------------------------------
283 // Create a fake URL from an existing CGI
284 //----------------------------------------------------------------------
285 char *pathWithNull = new char[length+1];
286 memcpy( pathWithNull, path, length );
287 pathWithNull[length] = 0;
288 std::ostringstream o;
289 o << "fake://fake:111/" << pathWithNull;
290 delete [] pathWithNull;
291
292 URL currentPath( o.str() );
293 URL::ParamsMap currentCgi = currentPath.GetParams();
294 MergeCGI( currentCgi, newCgi, replace );
295 currentPath.SetParams( currentCgi );
296 if( opathp )
297 *opathp = currentPath.GetPath();
298 if( !newPath.empty() )
299 currentPath.SetPath( newPath );
300 std::string newPathWitParams = currentPath.GetPathWithFilteredParams();
301
302 //----------------------------------------------------------------------
303 // Write the path with the new cgi appended to the message
304 //----------------------------------------------------------------------
305 uint32_t newDlen = req->header.dlen - length + newPathWitParams.size();
306 msg->ReAllocate( 24+newDlen );
307 req = (ClientRequest *)msg->GetBuffer();
308 path = msg->GetBuffer( 24 );
309 if( req->header.requestid == kXR_mv )
310 {
311 for( int i = 0; i < req->header.dlen; ++i, ++path )
312 if( *path == ' ' )
313 break;
314 ++path;
315 }
316 memcpy( path, newPathWitParams.c_str(), newPathWitParams.size() );
317 req->header.dlen = newDlen;
318 break;
319 }
320 case kXR_locate:
321 {
322 Env *env = DefaultEnv::GetEnv();
323 int preserveLocateTried = DefaultPreserveLocateTried;
324 env->GetInt( "PreserveLocateTried", preserveLocateTried );
325
326 if( !preserveLocateTried ) break;
327
328 //----------------------------------------------------------------------
329 // In case of locate we only want to preserve tried/triedrc CGI info
330 //----------------------------------------------------------------------
331 URL::ParamsMap triedCgi;
332 URL::ParamsMap::const_iterator itr = newCgi.find( "triedrc" );
333 if( itr != newCgi.end() )
334 triedCgi[itr->first] = itr->second;
335 itr = newCgi.find( "tried" );
336 if( itr != newCgi.end() )
337 triedCgi[itr->first] = itr->second;
338
339 //----------------------------------------------------------------------
340 // Is there anything to do?
341 //----------------------------------------------------------------------
342 if( triedCgi.empty() ) break;
343
344 //----------------------------------------------------------------------
345 // Get the pointer to the appropriate path
346 //----------------------------------------------------------------------
347 char *path = msg->GetBuffer( 24 );
348 size_t length = req->header.dlen;
349
350 //----------------------------------------------------------------------
351 // Create a fake URL from an existing CGI
352 //----------------------------------------------------------------------
353 std::string strpath( path, length );
354 std::ostringstream o;
355 o << "fake://fake:111/" << strpath;
356
357 URL currentPath( o.str() );
358 URL::ParamsMap currentCgi = currentPath.GetParams();
359 MergeCGI( currentCgi, triedCgi, replace );
360 currentPath.SetParams( currentCgi );
361 std::string pathWitParams = currentPath.GetPathWithFilteredParams();
362
363 //----------------------------------------------------------------------
364 // Write the path with the new cgi appended to the message
365 //----------------------------------------------------------------------
366 uint32_t newDlen = pathWitParams.size();
367 msg->ReAllocate( 24+newDlen );
368 req = (ClientRequest *)msg->GetBuffer();
369 path = msg->GetBuffer( 24 );
370 memcpy( path, pathWitParams.c_str(), pathWitParams.size() );
371 req->header.dlen = newDlen;
372 break;
373 }
374 }
376 }
struct ClientRequestHdr header
Definition XProtocol.hh:887
kXR_unt16 requestid
Definition XProtocol.hh:159
@ kXR_open
Definition XProtocol.hh:123
@ kXR_mkdir
Definition XProtocol.hh:121
@ kXR_chmod
Definition XProtocol.hh:115
@ kXR_rm
Definition XProtocol.hh:127
@ kXR_rmdir
Definition XProtocol.hh:128
@ kXR_truncate
Definition XProtocol.hh:141
@ kXR_mv
Definition XProtocol.hh:122
@ kXR_stat
Definition XProtocol.hh:130
@ kXR_locate
Definition XProtocol.hh:140
static void MergeCGI(URL::ParamsMap &cgi1, const URL::ParamsMap &cgi2, bool replace)
Merge cgi2 into cgi1.
std::map< std::string, std::string > ParamsMap
Definition XrdClURL.hh:33
static void SetDescription(Message *msg)
Get the description of a message.
const int DefaultPreserveLocateTried

References XrdCl::DefaultPreserveLocateTried, ClientRequestHdr::dlen, XrdCl::Buffer::GetBuffer(), XrdCl::DefaultEnv::GetEnv(), XrdCl::Env::GetInt(), XrdCl::URL::GetParams(), XrdCl::URL::GetPath(), XrdCl::URL::GetPathWithFilteredParams(), ClientRequest::header, kXR_chmod, kXR_locate, kXR_mkdir, kXR_mv, kXR_open, kXR_rm, kXR_rmdir, kXR_stat, kXR_truncate, MergeCGI(), XrdCl::Buffer::ReAllocate(), ClientRequestHdr::requestid, XrdCl::XRootDTransport::SetDescription(), XrdCl::URL::SetParams(), and XrdCl::URL::SetPath().

Here is the call graph for this function:

◆ SendMessage()

XRootDStatus XrdCl::MessageUtils::SendMessage ( const URL & url,
Message * msg,
ResponseHandler * handler,
MessageSendParams & sendParams,
LocalFileHandler * lFileHandler )
static

Send message.

Definition at line 43 of file XrdClMessageUtils.cc.

48 {
49 //--------------------------------------------------------------------------
50 // Get the stuff needed to send the message
51 //--------------------------------------------------------------------------
52 Log *log = DefaultEnv::GetLog();
53 PostMaster *postMaster = DefaultEnv::GetPostMaster();
54 XRootDStatus st;
55
56 if( !postMaster )
57 return XRootDStatus( stError, errUninitialized );
58
59 log->Dump( XRootDMsg, "[%s] Sending message %s",
60 url.GetHostId().c_str(), msg->GetObfuscatedDescription().c_str() );
61
62 //--------------------------------------------------------------------------
63 // Get an instance of SID manager object
64 //--------------------------------------------------------------------------
65 std::shared_ptr<SIDManager> sidMgr( SIDMgrPool::Instance().GetSIDMgr( url ) );
66 ClientRequestHdr *req = (ClientRequestHdr*)msg->GetBuffer();
67
68 //--------------------------------------------------------------------------
69 // Allocate the SID and marshall the message
70 //--------------------------------------------------------------------------
71 st = sidMgr->AllocateSID( req->streamid );
72 if( !st.IsOK() )
73 {
74 log->Error( XRootDMsg, "[%s] Unable to allocate stream id",
75 url.GetHostId().c_str() );
76 return st;
77 }
78
79 //--------------------------------------------------------------------------
80 // Make sure that in case of checkpoint xeq request the embedded request
81 // SID is matching
82 //--------------------------------------------------------------------------
83 if( req->requestid == kXR_chkpoint )
84 {
85 ClientRequest *r = (ClientRequest*)req;
86 if( r->chkpoint.opcode == kXR_ckpXeq )
87 {
88 ClientRequest *xeq = (ClientRequest*) msg->GetBuffer( sizeof( ClientChkPointRequest ) );
89 xeq->header.streamid[0] = req->streamid[0];
90 xeq->header.streamid[1] = req->streamid[1];
91 }
92 }
93
95
96 //--------------------------------------------------------------------------
97 // Create and set up the message handler
98 //--------------------------------------------------------------------------
99 XRootDMsgHandler *msgHandler;
100 msgHandler = new XRootDMsgHandler( msg, handler, &url, sidMgr, lFileHandler );
101 msgHandler->SetExpiration( sendParams.expires );
102 msgHandler->SetRedirectAsAnswer( !sendParams.followRedirects );
103 msgHandler->SetOksofarAsAnswer( sendParams.chunkedResponse );
104 msgHandler->SetChunkList( sendParams.chunkList );
105 msgHandler->SetKernelBuffer( sendParams.kbuff );
106 msgHandler->SetRedirectCounter( sendParams.redirectLimit );
107 msgHandler->SetStateful( sendParams.stateful );
108 msgHandler->SetCrc32cDigests( std::move( sendParams.crc32cDigests ) );
109
110 if( sendParams.loadBalancer.url.IsValid() )
111 msgHandler->SetLoadBalancer( sendParams.loadBalancer );
112
113 HostList *list = 0;
114 if( sendParams.hostList )
115 {
116 list = sendParams.hostList;
117 sendParams.hostList = nullptr;
118 }
119 else
120 list = new HostList();
121 list->push_back( url );
122 msgHandler->SetHostList( list );
123
124 //--------------------------------------------------------------------------
125 // Send the message
126 //--------------------------------------------------------------------------
127 st = postMaster->Send( url, msg, msgHandler, sendParams.stateful,
128 sendParams.expires );
129 if( !st.IsOK() )
130 {
132 log->Error( XRootDMsg, "[%s] Unable to send the message %s: %s",
133 url.GetHostId().c_str(), msg->GetObfuscatedDescription().c_str(),
134 st.ToString().c_str() );
135
136 // we need to reassign req as its current value might have been
137 // invalidated in the meanwhile due to a realloc
138 req = (ClientRequestHdr*)msg->GetBuffer();
139 // Release the SID as the request was never send
140 sidMgr->ReleaseSID( req->streamid );
141 delete msgHandler;
142 return st;
143 }
144 return XRootDStatus();
145 }
kXR_char streamid[2]
Definition XProtocol.hh:158
static const int kXR_ckpXeq
Definition XProtocol.hh:218
@ kXR_chkpoint
Definition XProtocol.hh:125
struct ClientChkPointRequest chkpoint
Definition XProtocol.hh:890
static SIDMgrPool & Instance()

References ClientRequest::chkpoint, XrdCl::MessageSendParams::chunkedResponse, XrdCl::MessageSendParams::chunkList, XrdCl::MessageSendParams::crc32cDigests, XrdCl::Log::Dump(), XrdCl::Log::Error(), XrdCl::errUninitialized, XrdCl::MessageSendParams::expires, XrdCl::MessageSendParams::followRedirects, XrdCl::Buffer::GetBuffer(), XrdCl::URL::GetHostId(), XrdCl::DefaultEnv::GetLog(), XrdCl::Message::GetObfuscatedDescription(), XrdCl::DefaultEnv::GetPostMaster(), ClientRequest::header, XrdCl::MessageSendParams::hostList, XrdCl::SIDMgrPool::Instance(), XrdCl::Status::IsOK(), XrdCl::URL::IsValid(), XrdCl::MessageSendParams::kbuff, kXR_chkpoint, kXR_ckpXeq, XrdCl::MessageSendParams::loadBalancer, XrdCl::XRootDTransport::MarshallRequest(), ClientChkPointRequest::opcode, XrdCl::MessageSendParams::redirectLimit, ClientRequestHdr::requestid, XrdCl::PostMaster::Send(), XrdCl::XRootDMsgHandler::SetChunkList(), XrdCl::XRootDMsgHandler::SetCrc32cDigests(), XrdCl::XRootDMsgHandler::SetExpiration(), XrdCl::XRootDMsgHandler::SetHostList(), XrdCl::XRootDMsgHandler::SetKernelBuffer(), XrdCl::XRootDMsgHandler::SetLoadBalancer(), XrdCl::XRootDMsgHandler::SetOksofarAsAnswer(), XrdCl::XRootDMsgHandler::SetRedirectAsAnswer(), XrdCl::XRootDMsgHandler::SetRedirectCounter(), XrdCl::XRootDMsgHandler::SetStateful(), XrdCl::MessageSendParams::stateful, XrdCl::stError, ClientRequestHdr::streamid, XrdCl::Status::ToString(), XrdCl::XRootDTransport::UnMarshallRequest(), XrdCl::HostInfo::url, and XrdCl::XRootDMsg.

Referenced by XrdCl::FileSystemData::Send().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WaitForResponse()

template<class Type>
XrdCl::XRootDStatus XrdCl::MessageUtils::WaitForResponse ( SyncResponseHandler * handler,
Type *& response )
inlinestatic

Wait for the response.

Definition at line 168 of file XrdClMessageUtils.hh.

171 {
172 handler->WaitForResponse();
173
174 AnyObject *resp = handler->GetResponse();
175 XRootDStatus *status = handler->GetStatus();
176 XRootDStatus ret( *status );
177 delete status;
178
179 if( ret.IsOK() )
180 {
181 if( !resp )
182 return XRootDStatus( stError, errInternal );
183 resp->Get( response );
184 resp->Set( (int *)0 );
185 delete resp;
186
187 if( !response )
188 return XRootDStatus( stError, errInternal );
189 }
190
191 return ret;
192 }
const uint16_t errInternal
Internal error.

References XrdCl::errInternal, XrdCl::AnyObject::Get(), XrdCl::SyncResponseHandler::GetResponse(), XrdCl::SyncResponseHandler::GetStatus(), XrdCl::Status::IsOK(), XrdCl::AnyObject::Set(), XrdCl::stError, and XrdCl::SyncResponseHandler::WaitForResponse().

Referenced by XrdCl::FileSystem::DeepLocate(), XrdCl::File::DelXAttr(), XrdCl::FileSystem::DelXAttr(), XrdCl::FileSystem::DirList(), XrdCl::File::Fcntl(), XrdCl::File::Fcntl(), XrdCl::File::GetXAttr(), XrdCl::FileSystem::GetXAttr(), XrdCl::File::ListXAttr(), XrdCl::FileSystem::ListXAttr(), XrdCl::FileSystem::Locate(), XrdCl::File::PgRead(), XrdCl::FileSystem::Prepare(), XrdCl::FileSystem::Protocol(), XrdCl::FileSystem::Query(), XrdCl::File::Read(), XrdCl::File::ReadV(), XrdCl::FileSystem::SendCache(), XrdCl::FileSystem::SendInfo(), XrdCl::File::SetXAttr(), XrdCl::FileSystem::SetXAttr(), XrdCl::File::Stat(), XrdCl::FileSystem::Stat(), XrdCl::FileSystem::StatVFS(), XrdCl::File::VectorRead(), and XrdCl::File::Visa().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WaitForStatus()

XRootDStatus XrdCl::MessageUtils::WaitForStatus ( SyncResponseHandler * handler)
inlinestatic

Wait and return the status of the query.

Definition at line 155 of file XrdClMessageUtils.hh.

156 {
157 handler->WaitForResponse();
158 XRootDStatus *status = handler->GetStatus();
159 XRootDStatus ret( *status );
160 delete status;
161 return ret;
162 }

References XrdCl::SyncResponseHandler::GetStatus(), and XrdCl::SyncResponseHandler::WaitForResponse().

Referenced by XrdCl::FileSystem::ChMod(), XrdCl::File::Clone(), XrdCl::File::Close(), XrdCl::FileSystem::MkDir(), XrdCl::FileSystem::Mv(), XrdCl::File::Open(), XrdCl::File::OpenUsingTemplate(), XrdCl::File::PgWrite(), XrdCl::FileSystem::Ping(), XrdCl::RedirectorRegistry::RegisterAndWait(), XrdCl::FileSystem::Rm(), XrdCl::FileSystem::RmDir(), XrdCl::File::Sync(), XrdCl::File::Truncate(), XrdCl::FileSystem::Truncate(), XrdCl::File::VectorWrite(), XrdCl::File::Write(), XrdCl::File::Write(), XrdCl::File::Write(), and XrdCl::File::WriteV().

Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following files: