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)
 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::Close(), XrdCl::FileSystem::DirList(), XrdCl::FileStateHandler::Fcntl(), XrdCl::FileSystem::Locate(), XrdCl::FileSystem::MkDir(), XrdCl::FileSystem::Mv(), XrdCl::FileStateHandler::Open(), XrdCl::FileStateHandler::PgReadImpl(), XrdCl::FileStateHandler::PgWriteImpl(), XrdCl::FileSystem::Ping(), XrdCl::FileSystem::Prepare(), 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 286 of file XrdClMessageUtils.hh.

289 {
290 ClientRequestHdr *hdr = reinterpret_cast<ClientRequestHdr*>( msg->GetBuffer() );
291
292 std::vector<char> xattrvec;
293 Status st = MessageUtils::CreateXAttrVec( vec, xattrvec );
294 if( !st.IsOK() )
295 return st;
296
297 // update body size in the header
298 hdr->dlen = path.size() + 1;
299 hdr->dlen += xattrvec.size();
300
301 // append the body
302 size_t offset = sizeof( ClientRequestHdr );
303 msg->Append( path.c_str(), path.size() + 1, offset );
304 offset += path.size() + 1;
305 msg->Append( xattrvec.data(), xattrvec.size(), offset );
306
307 return Status();
308 }
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 455 of file XrdClMessageUtils.cc.

457 {
458 if( attrs.empty() )
459 return Status();
460
461 if( attrs.size() > xfaLimits::kXR_faMaxVars )
462 return Status( stError, errInvalidArgs );
463
464 //----------------------------------------------------------------------
465 // Calculate the name and value vector lengths
466 //----------------------------------------------------------------------
467
468 // 2 bytes for rc + 1 byte for null character at the end
469 static const int name_overhead = 3;
470
471 size_t nlen = 0;
472 for( auto itr = attrs.begin(); itr != attrs.end(); ++itr )
473 nlen += itr->size() + name_overhead;
474
475 if( nlen > xfaLimits::kXR_faMaxNlen )
476 return Status( stError, errInvalidArgs );
477
478 //----------------------------------------------------------------------
479 // Create name vector
480 //----------------------------------------------------------------------
481 nvec.resize( nlen, 0 );
482 char *nptr = nvec.data();
483
484 for( auto itr = attrs.begin(); itr != attrs.end(); ++itr )
485 nptr = ClientFattrRequest::NVecInsert( itr->c_str(), nptr );
486
487 return Status();
488 }
@ kXR_faMaxVars
Definition XProtocol.hh:280
@ kXR_faMaxNlen
Definition XProtocol.hh:281
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:172

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 404 of file XrdClMessageUtils.cc.

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

References XrdCl::errInvalidArgs, kXR_faMaxNlen, kXR_faMaxVars, kXR_faMaxVlen, XrdCl::NullRef< Response >::value, 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 378 of file XrdClMessageUtils.cc.

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

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::Close(), XrdCl::FileSystem::DirList(), XrdCl::FileStateHandler::Fcntl(), XrdCl::FileSystem::Locate(), XrdCl::FileSystem::MkDir(), XrdCl::FileSystem::Mv(), XrdCl::FileStateHandler::Open(), XrdCl::FileStateHandler::PgReadImpl(), XrdCl::FileStateHandler::PgWriteImpl(), XrdCl::FileSystem::Ping(), XrdCl::FileSystem::Prepare(), 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 )
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

Definition at line 250 of file XrdClMessageUtils.cc.

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