63 o <<
"WaitTask for: 0x" << handler->
GetRequest();
67 virtual time_t Run( time_t now )
69 pHandler->WaitDone( now );
95 virtual void Run(
void *arg )
97 pHandler->HandleResponse();
113 if( pOksofarAsAnswer )
116 while( pResponse ) pCV.
Wait();
123 log->
Warning(
ExDbgMsg,
"[%s] MsgHandler is examining a response although "
124 "it already owns a response: 0x%x (message: %s ).",
130 if( msg->GetSize() < 8 )
170 pBodyReader->SetDataLength( dlen );
227 log->
Dump(
XRootDMsg,
"[%s] Got a kXR_oksofar response to request "
231 if( !pOksofarAsAnswer )
233 pPartialResps.emplace_back( std::move( pResponse ) );
244 pTimeoutFence.store(
true, std::memory_order_relaxed );
253 pTimeoutFence.store(
true, std::memory_order_relaxed );
262 log->
Dump(
XRootDMsg,
"[%s] Got a kXR_status response to request "
281 pTimeoutFence.store(
true, std::memory_order_relaxed );
348 pPartialResps.push_back( std::move( pResponse ) );
361 pPageReader.reset(
new AsyncPageReader( *pChunkList, pCrc32cDigests ) );
362 pPageReader->SetRsp( rspst );
377 pResponse->GetCursor() )
416 int *qryResponse = 0;
418 qryResult.
Get( qryResponse );
419 pHosts->back().flags = *qryResponse;
delete qryResponse; qryResponse = 0;
421 qryResult.
Get( qryResponse );
422 pHosts->back().protocol = *qryResponse;
delete qryResponse;
446 pAggregatedWaitTime = 0;
455 log->
Dump(
XRootDMsg,
"[%s] Got a kXR_ok response to request %s",
465 log->
Dump(
XRootDMsg,
"[%s] Got a kXR_status response to request %s",
478 log->
Dump(
XRootDMsg,
"[%s] Got a kXR_oksofar response to request %s",
491 char *errmsg =
new char[rsp->
hdr.
dlen-3]; errmsg[rsp->
hdr.
dlen-4] = 0;
492 memcpy( errmsg, rsp->
body.error.errmsg, rsp->
hdr.
dlen-4 );
493 log->
Dump(
XRootDMsg,
"[%s] Got a kXR_error response to request %s "
517 char *urlInfoBuff =
new char[rsp->
hdr.
dlen-3];
518 urlInfoBuff[rsp->
hdr.
dlen-4] = 0;
519 memcpy( urlInfoBuff, rsp->
body.redirect.host, rsp->
hdr.
dlen-4 );
520 std::string urlInfo = urlInfoBuff;
521 delete [] urlInfoBuff;
523 "message %s: %s, port %d", pUrl.
GetHostId().c_str(),
525 rsp->
body.redirect.port );
530 if( !pRedirectCounter )
533 "message %s, the last known error is: %s",
549 uint32_t flags = pHosts->back().flags;
550 if( !pHasLoadBalancer )
561 pLoadBalancer = pHosts->back();
562 log->
Dump(
XRootDMsg,
"[%s] Current server has been assigned "
563 "as a load-balancer for message %s",
566 HostList::iterator it;
567 for( it = pHosts->begin(); it != pHosts->end(); ++it )
568 it->loadBalancer =
false;
569 pHosts->back().loadBalancer =
true;
580 pEffectiveDataServerUrl =
new URL( pHosts->back().url );
585 std::vector<std::string> urlComponents;
589 std::ostringstream o;
591 o << urlComponents[0];
592 if( rsp->
body.redirect.port > 0 )
593 o <<
":" << rsp->
body.redirect.port <<
"/";
594 else if( rsp->
body.redirect.port < 0 )
609 std::string url( rsp->
body.redirect.host, rsp->
hdr.
dlen-4 );
615 std::string url( rsp->
body.redirect.host, rsp->
hdr.
dlen-4 );
617 pRedirectAsAnswer =
true;
621 URL newUrl =
URL( o.str() );
626 pUrl.
GetHostId().c_str(), urlInfo.c_str() );
643 std::ostringstream ossXrd;
646 for(URL::ParamsMap::const_iterator it = urlParams.begin();
647 it != urlParams.end(); ++it )
649 if( it->first.compare( 0, 4,
"xrd." ) &&
650 it->first.compare( 0, 6,
"xrdcl." ) )
653 ossXrd << it->first <<
'=' << it->second <<
'&';
656 std::string xrdCgi = ossXrd.str();
657 pRedirectUrl = newUrl.
GetURL();
660 if( urlComponents.size() > 1 )
663 pRedirectUrl += urlComponents[1];
664 std::ostringstream o;
665 o <<
"fake://fake:111//fake?";
666 o << urlComponents[1];
668 if( urlComponents.size() == 3 )
669 o <<
'?' << urlComponents[2];
675 pRedirectUrl += xrdCgi;
678 cgiURL =
URL( o.str() );
683 std::ostringstream o;
684 o <<
"fake://fake:111//fake?";
686 cgiURL =
URL( o.str() );
688 pRedirectUrl += xrdCgi;
698 pRedirectAsAnswer =
true;
700 if( pRedirectAsAnswer )
711 Status st = RewriteRequestRedirect( newUrl );
738 uint32_t waitSeconds = 0;
742 char *infoMsg =
new char[rsp->
hdr.
dlen-3];
744 memcpy( infoMsg, rsp->
body.wait.infomsg, rsp->
hdr.
dlen-4 );
745 log->
Dump(
XRootDMsg,
"[%s] Got kXR_wait response of %d seconds to "
746 "message %s: %s", pUrl.
GetHostId().c_str(),
750 waitSeconds = rsp->
body.wait.seconds;
754 log->
Dump(
XRootDMsg,
"[%s] Got kXR_wait response of 0 seconds to "
759 pAggregatedWaitTime += waitSeconds;
764 if( OmitWait( *pRequest, pLoadBalancer.
url ) )
768 if( pAggregatedWaitTime > maxWait )
780 Status st = RewriteRequestWait();
792 time_t resendTime = ::time(0)+waitSeconds;
794 if( resendTime < pExpiration )
796 log->
Debug(
ExDbgMsg,
"[%s] Scheduling WaitTask for MsgHandler: 0x%x (message: %s ).",
801 taskMgr->
RegisterTask(
new WaitTask(
this ), resendTime );
805 log->
Debug(
XRootDMsg,
"[%s] Wait time is too long, timing out %s",
830 log->
Dump(
XRootDMsg,
"[%s] Got kXR_waitresp response of %d seconds to "
832 rsp->
body.waitresp.seconds,
842 log->
Dump(
XRootDMsg,
"[%s] Got unrecognized response %d to "
861 log->
Dump(
XRootDMsg,
"[%s] Stream event reported for msg %s",
867 if( pTimeoutFence.load( std::memory_order_relaxed ) )
870 HandleError( status );
879 uint32_t &bytesRead )
885 return pPageReader->Read( *socket, bytesRead );
887 return pBodyReader->Read( *socket, bytesRead );
904 log->
Dump(
XRootDMsg,
"[%s] Message %s has been successfully sent.",
907 log->
Debug(
ExDbgMsg,
"[%s] Moving MsgHandler: 0x%x (message: %s ) from out-queue to in-queue.",
918 log->
Error(
XRootDMsg,
"[%s] Impossible to send message %s. Trying to "
921 HandleError( status );
948 uint32_t &bytesWritten )
953 if( !pChunkList->empty() && !pCrc32cDigests.empty() )
963 int fLen = 0, lLen = 0;
971 uint32_t digest = htonl( pCrc32cDigests[pPgWrtCurrentPageNb] );
972 memcpy( pPgWrtCksumBuff.
GetBuffer(), &digest,
sizeof( uint32_t ) );
975 uint32_t btsLeft = chunk.
length - pAsyncOffset;
976 uint32_t pglen = ( pPgWrtCurrentPageNb == 0 ? fLen :
XrdSys::PageSize ) - pPgWrtCurrentPageOffset;
977 if( pglen > btsLeft ) pglen = btsLeft;
978 char* pgbuf =
static_cast<char*
>( chunk.
buffer ) + pAsyncOffset;
983 while( pPgWrtCksumBuff.
GetCursor() <
sizeof( uint32_t ) )
985 uint32_t dgstlen =
sizeof( uint32_t ) - pPgWrtCksumBuff.
GetCursor();
988 Status st = socket->
Send( dgstbuf, dgstlen, btswrt );
989 if( !st.
IsOK() )
return st;
990 bytesWritten += btswrt;
996 Status st = socket->
Send( pgbuf, pglen, btswrt );
997 if( !st.
IsOK() )
return st;
1001 bytesWritten += btswrt;
1002 pAsyncOffset += btswrt;
1008 ++pPgWrtCurrentPageNb;
1009 if( pPgWrtCurrentPageNb < nbpgs )
1013 uint32_t digest = htonl( pCrc32cDigests[pPgWrtCurrentPageNb] );
1014 memcpy( pPgWrtCksumBuff.
GetBuffer(), &digest,
sizeof( uint32_t ) );
1018 if( pglen > btsLeft ) pglen = btsLeft;
1020 pPgWrtCurrentPageOffset = 0;
1024 pPgWrtCurrentPageOffset += btswrt;
1028 else if( !pChunkList->empty() )
1030 size_t size = pChunkList->size();
1031 for(
size_t i = pAsyncChunkIndex ; i < size; ++i )
1033 char *buffer = (
char*)(*pChunkList)[i].buffer;
1034 uint32_t size = (*pChunkList)[i].length;
1035 size_t leftToBeWritten = size - pAsyncOffset;
1037 while( leftToBeWritten )
1040 Status st = socket->
Send( buffer + pAsyncOffset, leftToBeWritten, btswrt );
1041 bytesWritten += btswrt;
1043 pAsyncOffset += btswrt;
1044 leftToBeWritten -= btswrt;
1064 log->
Debug(
XRootDMsg,
"[%s] Channel is encrypted: cannot use kernel buffer.",
1070 pChunkList->push_back(
ChunkInfo( 0, ret, ubuff ) );
1077 while( !pKBuff->
Empty() )
1081 bytesWritten += btswrt;
1085 log->
Debug(
XRootDMsg,
"[%s] Request %s payload (kernel buffer) transferred to socket.",
1106 pTimeoutFence.store(
false, std::memory_order_relaxed );
1112 void XRootDMsgHandler::HandleResponse()
1122 log->
Debug(
ExDbgMsg,
"[%s] Calling MsgHandler: 0x%x (message: %s ) "
1128 if( status->
IsOK() )
1130 Status st = ParseResponse( response );
1145 pRdirEntry->status = *status;
1146 pRedirectTraceBack.push_back( std::move( pRdirEntry ) );
1157 if( pSidMgr && finalrsp )
1160 if( status->
IsOK() || !pMsgInFly ||
1165 HostList *hosts = pHosts.release();
1167 pHosts.reset(
new HostList( *hosts ) );
1184 pTimeoutFence.store(
false, std::memory_order_relaxed );
1193 XRootDStatus *XRootDMsgHandler::ProcessStatus()
1195 XRootDStatus *st =
new XRootDStatus( pStatus );
1200 if( !pStatus.
IsOK() && rsp )
1204 st->errNo = rsp->
body.error.errnum;
1207 std::string errmsg( rsp->
body.error.errmsg, rsp->
hdr.
dlen-5 );
1209 errmsg +=
" Last seen error: " + pLastError.
ToString();
1210 st->SetErrorMessage( errmsg );
1213 st->SetErrorMessage( pRedirectUrl );
1222 Status XRootDMsgHandler::ParseResponse( AnyObject *&response )
1236 log->Error(
XRootDMsg,
"Internal Error: unable to process redirect" );
1241 uint32_t length = 0;
1247 if( pPartialResps.empty() )
1249 buffer = rsp->
body.buffer.data;
1258 for( uint32_t i = 0; i < pPartialResps.size(); ++i )
1265 buff.Allocate( length );
1266 uint32_t offset = 0;
1267 for( uint32_t i = 0; i < pPartialResps.size(); ++i )
1270 buff.Append( part->
body.buffer.data, part->
hdr.
dlen, offset );
1273 buff.Append( rsp->
body.buffer.data, rsp->
hdr.
dlen, offset );
1274 buffer = buff.GetBuffer();
1305 AnyObject *obj =
new AnyObject();
1307 char *nullBuffer =
new char[length+1];
1308 nullBuffer[length] = 0;
1309 memcpy( nullBuffer, buffer, length );
1311 log->Dump(
XRootDMsg,
"[%s] Parsing the response to %s as "
1312 "LocateInfo: %s", pUrl.
GetHostId().c_str(),
1314 LocationInfo *data =
new LocationInfo();
1316 if( data->ParseServerResponse( nullBuffer ) ==
false )
1320 delete [] nullBuffer;
1323 delete [] nullBuffer;
1335 AnyObject *obj =
new AnyObject();
1342 StatInfoVFS *data =
new StatInfoVFS();
1344 char *nullBuffer =
new char[length+1];
1345 nullBuffer[length] = 0;
1346 memcpy( nullBuffer, buffer, length );
1348 log->Dump(
XRootDMsg,
"[%s] Parsing the response to %s as "
1349 "StatInfoVFS: %s", pUrl.
GetHostId().c_str(),
1352 if( data->ParseServerResponse( nullBuffer ) ==
false )
1356 delete [] nullBuffer;
1359 delete [] nullBuffer;
1368 StatInfo *data =
new StatInfo();
1370 char *nullBuffer =
new char[length+1];
1371 nullBuffer[length] = 0;
1372 memcpy( nullBuffer, buffer, length );
1374 log->Dump(
XRootDMsg,
"[%s] Parsing the response to %s as StatInfo: "
1378 if( data->ParseServerResponse( nullBuffer ) ==
false )
1382 delete [] nullBuffer;
1385 delete [] nullBuffer;
1398 log->Dump(
XRootDMsg,
"[%s] Parsing the response to %s as ProtocolInfo",
1404 log->Error(
XRootDMsg,
"[%s] Got invalid redirect response.",
1409 AnyObject *obj =
new AnyObject();
1410 ProtocolInfo *data =
new ProtocolInfo( rsp->
body.protocol.pval,
1411 rsp->
body.protocol.flags );
1422 AnyObject *obj =
new AnyObject();
1423 log->Dump(
XRootDMsg,
"[%s] Parsing the response to %s as "
1424 "DirectoryList", pUrl.
GetHostId().c_str(),
1431 DirectoryList *data =
new DirectoryList();
1432 data->SetParentName( path );
1435 char *nullBuffer =
new char[length+1];
1436 nullBuffer[length] = 0;
1437 memcpy( nullBuffer, buffer, length );
1439 bool invalidrsp =
false;
1441 if( !pDirListStarted )
1444 pDirListStarted =
true;
1446 invalidrsp = !data->ParseServerResponse( pUrl.
GetHostId(), nullBuffer );
1449 invalidrsp = !data->ParseServerResponse( pUrl.
GetHostId(), nullBuffer, pDirListWithStat );
1455 delete [] nullBuffer;
1459 delete [] nullBuffer;
1470 log->Dump(
XRootDMsg,
"[%s] Parsing the response to %s as OpenInfo",
1476 log->Error(
XRootDMsg,
"[%s] Got invalid open response.",
1481 AnyObject *obj =
new AnyObject();
1482 StatInfo *statInfo = 0;
1489 log->Dump(
XRootDMsg,
"[%s] Parsing StatInfo in response to %s",
1495 char *nullBuffer =
new char[rsp->
hdr.
dlen-11];
1496 nullBuffer[rsp->
hdr.
dlen-12] = 0;
1497 memcpy( nullBuffer, buffer+12, rsp->
hdr.
dlen-12 );
1499 statInfo =
new StatInfo();
1500 if( statInfo->ParseServerResponse( nullBuffer ) ==
false )
1505 delete [] nullBuffer;
1508 if( rsp->
hdr.
dlen < 12 || !statInfo )
1510 log->Error(
XRootDMsg,
"[%s] Unable to parse StatInfo in response "
1518 OpenInfo *data =
new OpenInfo( (uint8_t*)buffer,
1519 pResponse->GetSessionId(),
1531 log->Dump(
XRootDMsg,
"[%s] Parsing the response to %s as ChunkInfo",
1535 for( uint32_t i = 0; i < pPartialResps.size(); ++i )
1541 if( pPartialResps[i]->GetSize() > 8 )
1548 if( pResponse->GetSize() > 8 )
1553 return pBodyReader->GetResponse( response );
1561 log->Dump(
XRootDMsg,
"[%s] Parsing the response to %s as PageInfo",
1568 ChunkInfo chunk = pChunkList->front();
1569 bool sizeMismatch =
false;
1570 uint32_t currentOffset = 0;
1571 char *cursor = (
char*)chunk.buffer;
1572 for( uint32_t i = 0; i < pPartialResps.size(); ++i )
1582 if( currentOffset + datalen > chunk.length )
1584 sizeMismatch =
true;
1588 currentOffset += datalen;
1593 size_t datalen = rspst->
status.
bdy.
dlen - NbPgPerRsp( rspst->
info.pgread.offset,
1595 if( currentOffset + datalen <= chunk.length )
1596 currentOffset += datalen;
1598 sizeMismatch =
true;
1603 if( pChunkStatus.front().sizeError || sizeMismatch )
1605 log->Error(
XRootDMsg,
"[%s] Handling response to %s: user supplied "
1606 "buffer is too small for the received data.",
1612 AnyObject *obj =
new AnyObject();
1613 PageInfo *pgInfo =
new PageInfo( chunk.offset, currentOffset, chunk.buffer,
1614 std::move( pCrc32cDigests) );
1626 std::vector<std::tuple<uint64_t, uint32_t>> retries;
1633 retries.reserve( pgcnt );
1637 for(
size_t i = 0; i < pgcnt; ++i )
1640 if( i == 0 ) len = cse->
dlFirst;
1641 else if( i == pgcnt - 1 ) len = cse->
dlLast;
1642 retries.push_back( std::make_tuple( pgoffs[i], len ) );
1646 RetryInfo *info =
new RetryInfo( std::move( retries ) );
1647 AnyObject *obj =
new AnyObject();
1660 log->Dump(
XRootDMsg,
"[%s] Parsing the response to 0x%x as "
1661 "VectorReadInfo", pUrl.
GetHostId().c_str(),
1664 for( uint32_t i = 0; i < pPartialResps.size(); ++i )
1670 if( pPartialResps[i]->GetSize() > 8 )
1677 if( pResponse->GetSize() > 8 )
1682 return pBodyReader->GetResponse( response );
1690 int len = rsp->hdr.dlen;
1691 char* data = rsp->body.buffer.data;
1693 return ParseXAttrResponse( data, len, response );
1704 AnyObject *obj =
new AnyObject();
1705 log->Dump(
XRootDMsg,
"[%s] Parsing the response to %s as BinaryData",
1710 data->Allocate( length );
1711 data->Append( buffer, length );
1724 Status XRootDMsgHandler::ParseXAttrResponse(
char *data,
size_t len,
1725 AnyObject *&response )
1738 if( !( status = ReadFromBuffer( data, len, nerrs ) ).IsOK() )
1742 if( !( status = ReadFromBuffer( data, len, nattr ) ).IsOK() )
1745 std::vector<XAttrStatus> resp;
1747 for(
kXR_char i = 0; i < nattr; ++i )
1750 if( !( status = ReadFromBuffer( data, len, rc ) ).IsOK() )
1758 if( !( status = ReadFromBuffer( data, len, name ) ).IsOK() )
1763 resp.push_back( XAttrStatus( name, st ) );
1770 response =
new AnyObject();
1771 response->Set(
new std::vector<XAttrStatus>( std::move( resp ) ) );
1781 if( !( status = ReadFromBuffer( data, len, nerrs ) ).IsOK() )
1785 if( !( status = ReadFromBuffer( data, len, nattr ) ).IsOK() )
1788 std::vector<XAttr> resp;
1789 resp.reserve( nattr );
1792 for(
kXR_char i = 0; i < nattr; ++i )
1795 if( !( status = ReadFromBuffer( data, len, rc ) ).IsOK() )
1803 if( !( status = ReadFromBuffer( data, len, name ) ).IsOK() )
1808 resp.push_back( XAttr( name, st ) );
1812 for(
kXR_char i = 0; i < nattr; ++i )
1815 if( !( status = ReadFromBuffer( data, len, vlen ) ).IsOK() )
1817 vlen = ntohl( vlen );
1820 if( !( status = ReadFromBuffer( data, len, vlen, value ) ).IsOK() )
1823 resp[i].value.swap( value );
1830 response =
new AnyObject();
1831 response->Set(
new std::vector<XAttr>( std::move( resp ) ) );
1839 std::vector<XAttr> resp;
1844 if( !( status = ReadFromBuffer( data, len, name ) ).IsOK() )
1848 if( !( status = ReadFromBuffer( data, len, vlen ) ).IsOK() )
1850 vlen = ntohl( vlen );
1853 if( !( status = ReadFromBuffer( data, len, vlen, value ) ).IsOK() )
1856 resp.push_back( XAttr( name, value ) );
1860 response =
new AnyObject();
1861 response->Set(
new std::vector<XAttr>( std::move( resp ) ) );
1875 Status XRootDMsgHandler::RewriteRequestRedirect(
const URL &newUrl )
1883 std::string xrdCgi =
"";
1884 std::ostringstream ossXrd;
1885 for(URL::ParamsMap::const_iterator it = newCgi.begin(); it != newCgi.end(); ++it )
1887 if( it->first.compare( 0, 4,
"xrd." ) )
1889 ossXrd << it->first <<
'=' << it->second <<
'&';
1892 xrdCgi = ossXrd.str();
1902 std::string surl = newUrl.
GetURL();
1903 (surl.find(
'?') == std::string::npos) ? (surl +=
'?') :
1904 ((*surl.rbegin() !=
'&') ? (surl +=
'&') : (surl +=
""));
1909 log->Error(
XRootDMsg,
"[%s] Failed to build redirection URL from data:"
1910 "%s", surl.c_str());
1927 Status XRootDMsgHandler::RewriteRequestWait()
1962 void XRootDMsgHandler::HandleError( XRootDStatus status )
1970 if( pSidMgr && pMsgInFly && (
1981 if( !noreplicas ) pLastError = status;
1984 log->Debug(
XRootDMsg,
"[%s] Handling error while processing %s: %s.",
1986 status.ToString().c_str() );
1992 if( status.IsFatal() && status.code ==
errTlsError && status.errNo == EAGAIN )
1994 if( pSslErrCnt < MaxSslErrRetry )
1996 status.status &= ~stFatal;
2014 if( RetriableErrorResponse( status ) )
2016 UpdateTriedCGI(status.errNo);
2018 SwitchOnRefreshFlag();
2039 log->Error(
XRootDMsg,
"[%s] Unable to get the response to request %s",
2061 if( !status.IsFatal() && IsRetriable() )
2063 log->Info(
XRootDMsg,
"[%s] Retrying request: %s.",
2088 if( pRdirEntry ) pRedirectTraceBack.push_back( std::move( pRdirEntry ) );
2089 pRdirEntry.reset(
new RedirectEntry( pUrl.
GetLocation(), url.GetLocation(), entryType ) );
2093 pHosts->push_back( url );
2105 pSidMgr->ReleaseSID( req->
streamid );
2112 if( !url.IsLocalFile() )
2115 Status st = pSidMgr->AllocateSID( req->
streamid );
2118 log->Error(
XRootDMsg,
"[%s] Impossible to send message %s.",
2130 log->Debug(
ExDbgMsg,
"[%s] Metaling redirection for MsgHandler: 0x%x (message: %s ).",
2134 return pPostMaster->
Redirect( pUrl, pRequest,
this );
2138 HandleLocalRedirect( &pUrl );
2143 log->Debug(
ExDbgMsg,
"[%s] Retry at server MsgHandler: 0x%x (message: %s ).",
2146 return pPostMaster->
Send( pUrl, pRequest,
this,
true, pExpiration );
2153 void XRootDMsgHandler::UpdateTriedCGI(uint32_t errNo)
2163 if( pEffectiveDataServerUrl )
2166 delete pEffectiveDataServerUrl;
2167 pEffectiveDataServerUrl = 0;
2178 {
if (errNo ==
kXR_NotFound) cgi[
"triedrc"] =
"enoent";
2179 else if (errNo ==
kXR_IOError) cgi[
"triedrc"] =
"ioerr";
2180 else if (errNo ==
kXR_FSError) cgi[
"triedrc"] =
"fserr";
2191 HostList::reverse_iterator it;
2192 for( it = pHosts->rbegin()+1; it != pHosts->rend(); ++it )
2194 if( it->loadBalancer )
2197 tried +=
"," + it->url.GetHostName();
2204 cgi[
"tried"] = tried;
2213 void XRootDMsgHandler::SwitchOnRefreshFlag()
2239 void XRootDMsgHandler::HandleRspOrQueue()
2242 if( jobMgr->IsWorker() )
2247 log->Debug(
ExDbgMsg,
"[%s] Passing to the thread-pool MsgHandler: 0x%x (message: %s ).",
2257 void XRootDMsgHandler::HandleLocalRedirect( URL *url )
2260 log->Debug(
ExDbgMsg,
"[%s] Handling local redirect - MsgHandler: 0x%x (message: %s ).",
2264 if( !pLFileHandler )
2270 AnyObject *resp = 0;
2272 XRootDStatus st = pLFileHandler->
Open( url, pRequest, resp );
2290 bool XRootDMsgHandler::IsRetriable()
2294 if( value ==
"true" )
return true;
2307 "[%s] Not allowed to retry open request (OpenRecovery disabled): %s.",
2322 bool XRootDMsgHandler::OmitWait( Message &request,
const URL &url )
2325 if( !url.IsMetalink() )
2337 VirtualRedirector *redirector = registry.Get( url );
2341 if( redirector->Count( request ) > 1 )
2350 bool XRootDMsgHandler::RetriableErrorResponse(
const Status &status )
2378 bool ret = pNotAuthorizedCounter < limit;
2379 ++pNotAuthorizedCounter;
2384 "[%s] Reached limit of NotAuthorized retries!",
2405 void XRootDMsgHandler::DumpRedirectTraceBack()
2407 if( pRedirectTraceBack.empty() )
return;
2409 std::stringstream sstrm;
2411 sstrm <<
"Redirect trace-back:\n";
2415 auto itr = pRedirectTraceBack.begin();
2416 sstrm <<
'\t' << counter <<
". " << (*itr)->ToString() <<
'\n';
2422 for( ; itr != pRedirectTraceBack.end(); ++itr, ++prev, ++counter )
2423 sstrm <<
'\t' << counter <<
". "
2424 << (*itr)->ToString( (*prev)->status.IsOK() ) <<
'\n';
2429 bool warn = !pStatus.
IsOK() &&
2436 log->Warning(
XRootDMsg, sstrm.str().c_str() );
2438 log->Debug(
XRootDMsg, sstrm.str().c_str() );
2443 template<
typename T>
2444 Status XRootDMsgHandler::ReadFromBuffer(
char *&buffer,
size_t &buflen, T& result )
2448 memcpy(&result, buffer,
sizeof(T));
2450 buffer +=
sizeof( T );
2451 buflen -=
sizeof( T );
2459 Status XRootDMsgHandler::ReadFromBuffer(
char *&buffer,
size_t &buflen, std::string &result )
2466 if( !( status = ReadFromBuffer( buffer, buflen, c ) ).IsOK() )
2479 Status XRootDMsgHandler::ReadFromBuffer(
char *&buffer,
size_t &buflen,
2480 size_t size, std::string &result )
2486 result.append( buffer, size );
struct ClientFattrRequest fattr
#define kXR_collapseRedir
ServerResponseStatus status
struct ClientDirlistRequest dirlist
static const int kXR_ckpXeq
struct ClientOpenRequest open
struct ServerResponseBody_Status bdy
struct ClientRequestHdr header
union ServerResponse::@18 body
struct ClientChkPointRequest chkpoint
struct ServerResponseHeader hdr
#define kXR_PROTOCOLVERSION
struct ClientStatRequest stat
struct ClientLocateRequest locate
union ServerResponseV2::@19 info
void Get(Type &object)
Retrieve the object being held.
void AdvanceCursor(uint32_t delta)
Advance the cursor.
char * GetBufferAtCursor()
Get the buffer pointer at the append cursor.
const char * GetBuffer(uint32_t offset=0) const
Get the message buffer.
void SetCursor(uint32_t cursor)
Set the cursor.
uint32_t GetCursor() const
Get append cursor.
static Log * GetLog()
Get default log.
static Env * GetEnv()
Get default client environment.
static bool HasStatInfo(const char *data)
Returns true if data contain stat info.
bool GetString(const std::string &key, std::string &value)
bool GetInt(const std::string &key, int &value)
virtual void Run(void *arg)
The job logic.
HandleRspJob(XrdCl::XRootDMsgHandler *handler)
Interface for a job to be run by the job manager.
void SetHostList(const HostList &hostList)
XRootDStatus Open(const std::string &url, uint16_t flags, uint16_t mode, ResponseHandler *handler, uint16_t timeout=0)
void Error(uint64_t topic, const char *format,...)
Report an error.
void Warning(uint64_t topic, const char *format,...)
Report a warning.
void Dump(uint64_t topic, const char *format,...)
Print a dump message.
void Debug(uint64_t topic, const char *format,...)
Print a debug 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.
The message representation used throughout the system.
const std::string & GetDescription() const
Get the description of the message.
uint64_t GetSessionId() const
Get the session ID the message is meant for.
@ More
there are more (non-raw) data to be read
@ Ignore
Ignore the message.
StreamEvent
Events that may have occurred to the stream.
@ Ready
The stream has become connected.
void CollapseRedirect(const URL &oldurl, const URL &newURL)
Collapse channel URL - replace the URL of the channel.
XRootDStatus Send(const URL &url, Message *msg, MsgHandler *handler, bool stateful, time_t expires)
TaskManager * GetTaskManager()
Get the task manager object user by the post master.
Status Redirect(const URL &url, Message *msg, MsgHandler *handler)
Status QueryTransport(const URL &url, uint16_t query, AnyObject &result)
JobManager * GetJobManager()
Get the job manager object user by the post master.
static RedirectorRegistry & Instance()
Returns reference to the single instance.
virtual void HandleResponseWithHosts(XRootDStatus *status, AnyObject *response, HostList *hostList)
static SIDMgrPool & Instance()
std::shared_ptr< SIDManager > GetSIDMgr(const URL &url)
virtual XRootDStatus Send(const char *buffer, size_t size, int &bytesWritten)
void RegisterTask(Task *task, time_t time, bool own=true)
Interface for a task to be run by the TaskManager.
std::string GetHostId() const
Get the host part of the URL (user:password@host:port)
bool IsMetalink() const
Is it a URL to a metalink.
const std::string & GetPassword() const
Get the password.
std::map< std::string, std::string > ParamsMap
bool FromString(const std::string &url)
Parse a string and fill the URL fields.
void SetPassword(const std::string &password)
Set the password.
void SetParams(const std::string ¶ms)
Set params.
const std::string & GetUserName() const
Get the username.
std::string GetURL() const
Get the URL.
std::string GetLocation() const
Get location (protocol://host:port/path)
const std::string & GetHostName() const
Get the name of the target host.
void SetProtocol(const std::string &protocol)
Set protocol.
const ParamsMap & GetParams() const
Get the URL params.
const std::string & GetProtocol() const
Get the protocol.
bool IsValid() const
Is the url valid.
void SetUserName(const std::string &userName)
Set the username.
static void splitString(Container &result, const std::string &input, const std::string &delimiter)
Split a string.
static bool CheckEC(const Message *req, const URL &url)
Check if this client can support given EC redirect.
Handle/Process/Forward XRootD messages.
virtual uint16_t Examine(std::shared_ptr< Message > &msg)
XRootDStatus WriteMessageBody(Socket *socket, uint32_t &bytesWritten)
friend class HandleRspJob
const Message * GetRequest() const
Get the request pointer.
virtual uint8_t OnStreamEvent(StreamEvent event, XRootDStatus status)
virtual XRootDStatus ReadMessageBody(Message *msg, Socket *socket, uint32_t &bytesRead)
virtual void OnStatusReady(const Message *message, XRootDStatus status)
The requested action has been performed and the status is available.
void WaitDone(time_t now)
virtual bool IsRaw() const
Are we a raw writer or not?
virtual void Process()
Process the message if it was "taken" by the examine action.
virtual uint16_t InspectStatusRsp()
virtual uint16_t GetSid() const
const std::string & GetErrorMessage() const
Get error message.
static void SetDescription(Message *msg)
Get the description of a message.
static XRootDStatus UnMarshallBody(Message *msg, uint16_t reqType)
Unmarshall the body of the incoming message.
static XRootDStatus UnMarshallRequest(Message *msg)
static XRootDStatus UnMarshalStatusBody(Message &msg, uint16_t reqType)
Unmarshall the body of the status response.
static XRootDStatus MarshallRequest(Message *msg)
Marshal the outgoing message.
static int csNum(off_t offs, int count)
Compute the required size of a checksum vector based on offset & length.
const uint16_t errRedirectLimit
const int DefaultMaxMetalinkWait
const uint16_t errErrorResponse
const uint16_t errTlsError
const uint16_t errOperationExpired
const uint16_t stFatal
Fatal error, it's still an error.
const uint16_t stError
An error occurred that could potentially be retried.
const uint16_t errNotFound
std::vector< HostInfo > HostList
const uint16_t errDataError
data is corrupted
const uint16_t errInternal
Internal error.
const uint16_t stOK
Everything went OK.
const uint16_t errInvalidResponse
const uint16_t errInvalidRedirectURL
const uint16_t errNotSupported
Buffer BinaryDataInfo
Binary buffer.
const uint16_t errOperationInterrupted
const uint16_t suContinue
const int DefaultNotAuthorizedRetryLimit
const uint16_t errRedirect
const uint16_t errAuthFailed
const uint16_t errInvalidMessage
none object for initializing empty Optional
static const int PageSize
ssize_t Move(KernelBuffer &kbuff, char *&ubuff)
Describe a data chunk for vector read.
void * buffer
length of the chunk
uint32_t length
offset in the file
Procedure execution status.
uint16_t code
Error type, or additional hints on what to do.
bool IsOK() const
We're fine.
std::string ToString() const
Create a string representation.
static const uint16_t ServerFlags
returns server flags
static const uint16_t ProtocolVersion
returns the protocol version