#include "Bytes.h"
#include "TError.h"
#include "TEnv.h"
#include "TSocket.h"
#include "TXNetFile.h"
#include "TROOT.h"
#include "TVirtualMonitoring.h"
#include "TFileStager.h"
#include "TFileCacheRead.h"
#include <XrdClient/XrdClient.hh>
#include <XrdClient/XrdClientConst.hh>
#include <XrdClient/XrdClientEnv.hh>
#include <XProtocol/XProtocol.hh>
#ifdef OLDXRDOUC
# include "XrdOuc/XrdOucPthread.hh"
#else
# include "XrdSys/XrdSysPthread.hh"
#endif
ClassImp(TXNetFile);
Bool_t TXNetFile::fgInitDone = kFALSE;
Bool_t TXNetFile::fgRootdBC = kTRUE;
TXNetFile::TXNetFile(const char *url, Option_t *option, const char* ftitle,
Int_t compress, Int_t netopt, Bool_t parallelopen,
const char *logicalurl) :
TNetFile((logicalurl ? logicalurl : url), ftitle, compress, kFALSE)
{
TUrl urlnoanchor(url);
EnvPutInt(NAME_DEBUG, gEnv->GetValue("XNet.Debug", -1));
if (!fgInitDone || strstr(urlnoanchor.GetOptions(),"checkenv")) {
SetEnv();
fgInitDone = kTRUE;
if (gEnv->GetValue("XNet.PrintTAG",0) == 1)
Info("TXNetFile","(eXtended TNetFile) %s",
gROOT->GetVersion());
}
urlnoanchor.SetAnchor("");
fInitMtx = new XrdSysRecMutex();
if (gMonitoringWriter) {
if (!fOpenPhases) {
fOpenPhases = new TList;
fOpenPhases->SetOwner();
}
gMonitoringWriter->SendFileOpenProgress(this, fOpenPhases, "xrdopen", kFALSE);
}
CreateXClient(urlnoanchor.GetUrl(), option, netopt, parallelopen);
}
TXNetFile::~TXNetFile()
{
if (IsOpen())
Close(0);
SafeDelete(fInitMtx);
}
void TXNetFile::FormUrl(TUrl uu, TString &uus)
{
uus = "root://";
if (strlen(uu.GetUser()) > 0) {
uus += uu.GetUser();
uus += "@";
}
if (strlen(uu.GetHost()) > 0) {
uus += uu.GetHost();
}
if (uu.GetPort() > 0) {
uus += ":";
uus += uu.GetPort();
}
uus += "/";
}
Int_t TXNetFile::ParseOptions(const char *opts,
Int_t &cachesz, Int_t &readaheadsz,
Int_t &rmpolicy, Int_t &mxredir)
{
static const char *keys[4] = { "cachesz=", "readaheadsz=", "rmpolicy=",
"mxredir=" };
Int_t fo = 0;
TString s(opts);
Int_t i = 0;
for (i = 0; i < 4; i++) {
Int_t j = s.Index(keys[i]);
if (j != kNPOS) {
TString val(s(j+strlen(keys[i]), s.Length()));
Int_t k = 0;
while (k < val.Length())
if (!TString(val(k++)).IsDigit())
break;
if (k < val.Length())
val.Remove(--k);
if (val.IsDigit()) {
fo++;
if (i == 0)
cachesz = val.Atoi();
else if (i == 1)
readaheadsz = val.Atoi();
else if (i == 2)
rmpolicy = val.Atoi();
else if (i == 3)
mxredir = val.Atoi();
}
}
}
if (gDebug > 0)
Info("ParseCacheOptions","found: cachesz = %d, readaheadsz = %d, "
"rmpolicy = %d, mxredir = %d",
cachesz, readaheadsz, rmpolicy, mxredir);
return fo;
}
void TXNetFile::CreateXClient(const char *url, Option_t *option, Int_t netopt,
Bool_t parallelopen)
{
#ifndef OLDXRDLOCATE
Int_t cachesz = -1, readaheadsz = -1, rmpolicy = -1, mxredir = -1, np = 0;
#endif
fClient = 0;
fNetopt = netopt;
gSystem->Setenv("XRDCLIENTMAXWAIT", Form("%d",TFile::GetOpenTimeout()));
if (GetOnlyStaged()) {
static TFileStager* fFileStager = 0;
if (!fFileStager)
fFileStager = TFileStager::Open(url);
if (fFileStager) {
if (!(fFileStager->IsStaged(url))) {
::Warning("TXNetFile","<%s> is not staged - StageOnly flag is set!",url);
goto zombie;
}
}
}
fIsRootd = kFALSE;
if (gEnv->GetValue("XNet.ForceParallelOpen", 0))
parallelopen = kTRUE;
fAsyncOpenStatus = (parallelopen) ? kAOSInProgress : fAsyncOpenStatus ;
Bool_t isRootd;
isRootd = kFALSE;
fClient = new XrdClient(url);
if (!fClient) {
fAsyncOpenStatus = (parallelopen) ? kAOSFailure : fAsyncOpenStatus ;
Error("CreateXClient","fatal error: new object creation failed -"
" out of system resources.");
gSystem->Abort();
goto zombie;
}
#ifndef OLDXRDLOCATE
np = ParseOptions(TUrl(url).GetOptions(),
cachesz, readaheadsz, rmpolicy, mxredir);
if (mxredir > 0) {
if (fClient->GetClientConn()) {
if (gDebug > 0)
Info("CreateXClient", "setting maxredir = %d", mxredir);
fClient->GetClientConn()->SetMaxRedirCnt(mxredir);
}
np--;
}
if (np > 0) {
if (gDebug > 0)
Info("CreateXClient", "setting cachesz = %d, readaheadsz = %d, "
"rmpolicy = %d",
cachesz, readaheadsz, rmpolicy);
fClient->SetCacheParameters(cachesz, readaheadsz, rmpolicy);
} else {
if (IsRaw())
fClient->SetCacheParameters(0, 0, 0);
}
#else
if (IsRaw()) {
EnvPutInt(NAME_READAHEADSIZE, 0);
}
#endif
if (!Open(option, parallelopen)) {
if (!fClient->IsOpen_wait()) {
if (gDebug > 1)
Info("CreateXClient", "remote file could not be open");
isRootd = (fClient->GetClientConn()->GetServerType() == kSTRootd);
if (isRootd) {
if (fgRootdBC) {
Int_t sd = fClient->GetClientConn()->GetOpenSockFD();
if (sd > -1) {
TSocket *s = new TSocket(sd);
s->SetOption(kNoBlock, 0);
Int_t rproto = GetRootdProtocol(s);
if (rproto < 0) {
Error("CreateXClient", "getting rootd server protocol");
goto zombie;
}
s->SetRemoteProtocol(rproto);
TUrl uut((fClient->GetClientConn()
->GetCurrentUrl()).GetUrl().c_str());
TString uu;
FormUrl(uut,uu);
if (gDebug > 2)
Info("CreateXClient"," url: %s",uu.Data());
s->SetUrl(uu.Data());
s->SetService("rootd");
s->SetServType(TSocket::kROOTD);
fIsRootd = kTRUE;
if (rproto > 13) {
TNetFile::Create(s, option, netopt);
} else {
TNetFile::Create(uu.Data(), option, netopt);
}
return;
} else {
Error("CreateXClient", "rootd: underlying socket undefined");
goto zombie;
}
} else {
if (gDebug > 0)
Info("CreateXClient", "rootd: fall back not enabled - closing");
goto zombie;
}
} else {
Error("CreateXClient", "open attempt failed on %s", fUrl.GetUrl());
goto zombie;
}
}
}
return;
zombie:
SafeDelete(fClient);
MakeZombie();
gDirectory = gROOT;
}
Int_t TXNetFile::GetRootdProtocol(TSocket *s)
{
Int_t rproto = -1;
UInt_t cproto = 0;
Int_t len = sizeof(cproto);
memcpy((char *)&cproto,
Form(" %d", TSocket::GetClientProtocol()),len);
Int_t ns = s->SendRaw(&cproto, len);
if (ns != len) {
::Error("TXNetFile::GetRootdProtocol",
"sending %d bytes to rootd server [%s:%d]",
len, (s->GetInetAddress()).GetHostName(), s->GetPort());
return -1;
}
Int_t ibuf[2] = {0};
len = sizeof(ibuf);
Int_t nr = s->RecvRaw(ibuf, len);
if (nr != len) {
::Error("TXNetFile::GetRootdProtocol",
"reading %d bytes from rootd server [%s:%d]",
len, (s->GetInetAddress()).GetHostName(), s->GetPort());
return -1;
}
Int_t kind = net2host(ibuf[0]);
if (kind == kROOTD_PROTOCOL) {
rproto = net2host(ibuf[1]);
} else {
kind = net2host(ibuf[1]);
if (kind == kROOTD_PROTOCOL) {
len = sizeof(rproto);
nr = s->RecvRaw(&rproto, len);
if (nr != len) {
::Error("TXNetFile::GetRootdProtocol",
"reading %d bytes from rootd server [%s:%d]",
len, (s->GetInetAddress()).GetHostName(), s->GetPort());
return -1;
}
rproto = net2host(rproto);
}
}
if (gDebug > 2)
::Info("TXNetFile::GetRootdProtocol",
"remote rootd: buf1: %d, buf2: %d rproto: %d",
net2host(ibuf[0]),net2host(ibuf[1]),rproto);
return rproto;
}
Bool_t TXNetFile::Open(Option_t *option, Bool_t doitparallel)
{
kXR_unt16 openOpt = 0;
memset(&openOpt, 0, sizeof(openOpt));
TString opt = option;
opt.ToUpper();
if (opt.BeginsWith("-") || opt.BeginsWith("F") || (opt == "+READ")) {
opt.Remove(0,1);
openOpt |= kXR_force;
}
Bool_t read = (opt == "READ");
Bool_t create = (opt == "CREATE" || opt == "NEW");
Bool_t recreate = (opt == "RECREATE");
Bool_t update = (opt == "UPDATE");
if (!create && !recreate && !update && !read) {
read = kTRUE;
opt = "READ";
}
fOption = opt;
if (create || update || recreate)
fWritable = 1;
if (update) {
if (gSystem->AccessPathName(fUrl.GetUrl(), kFileExists)) {
update = kFALSE;
create = kTRUE;
}
if (update) {
if (gSystem->AccessPathName(fUrl.GetUrl(), kWritePermission)) {
Error("Open", "no write permission, could not open file %s",
fUrl.GetUrl());
fAsyncOpenStatus = (doitparallel) ? kAOSFailure : fAsyncOpenStatus ;
return kFALSE;
}
openOpt |= kXR_open_updt;
}
}
if (create)
openOpt |= kXR_new;
if (recreate) {
openOpt |= kXR_delete;
create = kTRUE;
}
Bool_t mkpath = (gEnv->GetValue("XNet.Mkpath", 0) == 1) ? kTRUE : kFALSE;
char *p = (char*)strstr(fUrl.GetOptions(), "mkpath=");
if (p)
mkpath = (*(p + strlen("mkpath=")) == '1') ? kTRUE : kFALSE;
if (mkpath)
openOpt |= kXR_mkpath;
if (read)
openOpt |= kXR_open_read;
kXR_unt16 openMode = kXR_or | kXR_gr | kXR_ur | kXR_uw;
if (!fClient->Open(openMode, openOpt, doitparallel)) {
if (gDebug > 1)
Info("Open", "remote file could not be open");
fAsyncOpenStatus = (doitparallel) ? kAOSFailure : fAsyncOpenStatus ;
return kFALSE;
} else {
if (!doitparallel) {
Init(create);
if (TFile::IsZombie()) {
fClient->Close();
fWritable = 0;
return kFALSE;
}
}
}
return kTRUE;
}
Bool_t TXNetFile::ReadBuffer(char *buffer, Int_t bufferLength)
{
if (IsZombie()) {
Error("ReadBuffer", "ReadBuffer is not possible because object"
" is in 'zombie' state");
return kTRUE;
}
if (fIsRootd) {
if (gDebug > 1)
Info("ReadBuffer","Calling TNetFile::ReadBuffer");
return TNetFile::ReadBuffer(buffer, bufferLength);
}
if (!IsOpen()) {
Error("ReadBuffer","The remote file is not open");
return kTRUE;
}
Bool_t result = kFALSE;
if (bufferLength==0)
return 0;
Int_t st = 0;
if (GetCacheRead() && GetCacheRead()->IsAsyncReading()) {
st = ReadBufferViaCache(0, bufferLength);
if (st == 1)
fOffset -= bufferLength;
} else {
if (GetCacheRead()) {
st = ReadBufferViaCache(buffer, bufferLength);
if (st == 1)
return kFALSE;
}
}
if (!st) {
Int_t rAheadsiz = gEnv->GetValue("XNet.ReadAheadSize", DFLT_READAHEADSIZE);
#ifndef OLDXRDLOCATE
fClient->SetCacheParameters(-1, rAheadsiz, -1);
#else
EnvPutInt(NAME_READAHEADSIZE, rAheadsiz);
#endif
}
Int_t nr = fClient->Read(buffer, fOffset, bufferLength);
if (!nr)
return kTRUE;
if (gDebug > 1)
Info("ReadBuffer", "%d bytes of data read from offset"
" %lld (%d requested)", nr, fOffset, bufferLength);
fOffset += bufferLength;
if (!st) {
fBytesRead += nr;
fReadCalls++;
#ifdef WIN32
SetFileBytesRead(GetFileBytesRead() + nr);
SetFileReadCalls(GetFileReadCalls() + 1);
#else
fgBytesRead += nr;
fgReadCalls++;
#endif
}
if (gMonitoringWriter)
gMonitoringWriter->SendFileReadProgress(this);
return result;
}
Bool_t TXNetFile::ReadBufferAsync(Long64_t offs, Int_t bufferLength)
{
if (IsZombie()) {
Error("ReadBuffer", "ReadBuffer is not possible because object"
" is in 'zombie' state");
return kTRUE;
}
if (fIsRootd) {
if (gDebug > 1)
Error("ReadBufferAsync","Not supported for rootd");
return kTRUE;
}
if (!IsOpen()) {
Error("ReadBuffer","The remote file is not open");
return kTRUE;
}
Bool_t result = kFALSE;
if (bufferLength==0)
return 0;
SynchronizeCacheSize();
XReqErrorType nr = fClient->Read_Async(offs, bufferLength);
if (nr != kOK)
return kTRUE;
fBytesRead += bufferLength;
fReadCalls++;
#ifdef WIN32
SetFileBytesRead(GetFileBytesRead() + bufferLength);
SetFileReadCalls(GetFileReadCalls() + 1);
#else
fgBytesRead += bufferLength;
fgReadCalls++;
#endif
if (gDebug > 1)
Info("ReadBufferAsync", "%d bytes of data read request from offset"
" %lld", bufferLength, offs);
return result;
}
Bool_t TXNetFile::ReadBuffers(char *buf, Long64_t *pos, Int_t *len, Int_t nbuf)
{
if (IsZombie()) {
Error("ReadBuffers", "ReadBuffers is not possible because object"
" is in 'zombie' state");
return kTRUE;
}
if (fIsRootd) {
if (gDebug > 1)
Info("ReadBuffers","Calling TNetFile::ReadBuffers");
return TNetFile::ReadBuffers(buf, pos, len, nbuf);
}
if (!IsOpen()) {
Error("ReadBuffers","The remote file is not open");
return kTRUE;
}
if (!buf)
SynchronizeCacheSize();
Long64_t nr = fClient->ReadV(buf, pos, len, nbuf);
if (gDebug > 1)
Info("ReadBuffers", "response from ReadV(%d) nr: %d", nbuf, nr);
if (nr > 0) {
if (gDebug > 1)
Info("ReadBuffers", "%lld bytes of data read from a list of %d buffers",
nr, nbuf);
fBytesRead += nr;
fReadCalls++;
#ifdef WIN32
SetFileBytesRead(GetFileBytesRead() + nr);
SetFileReadCalls(GetFileReadCalls() + 1);
#else
fgBytesRead += nr;
fgReadCalls++;
#endif
if (gMonitoringWriter)
gMonitoringWriter->SendFileReadProgress(this);
return kFALSE;
}
if (gDebug > 1)
Info("ReadBuffers", "XrdClient->ReadV failed, executing TFile::ReadBuffers");
return TFile::ReadBuffers(buf, pos, len, nbuf);
}
Bool_t TXNetFile::WriteBuffer(const char *buffer, Int_t bufferLength)
{
if (IsZombie()) {
Error("WriteBuffer", "WriteBuffer is not possible because object"
" is in 'zombie' state");
return kTRUE;
}
if (!fWritable) {
if (gDebug > 1)
Info("WriteBuffer","file not writable");
return kTRUE;
}
if (fIsRootd) {
if (gDebug > 1)
Info("WriteBuffer","Calling TNetFile::WriteBuffer");
return TNetFile::WriteBuffer(buffer, bufferLength );
}
if (!IsOpen()) {
Error("WriteBuffer","The remote file is not open");
return kTRUE;
}
Int_t st;
if ((st = WriteBufferViaCache(buffer, bufferLength))) {
if (st == 2)
return kTRUE;
return kFALSE;
}
if (!fClient->Write(buffer, fOffset, bufferLength)) {
if (gDebug > 0)
Info("WriteBuffer",
"error writing %d bytes of data wrote to offset %Ld",
bufferLength , fOffset);
return kTRUE;
}
if (gDebug > 1)
Info("WriteBuffer", " %d bytes of data wrote to offset"
" %Ld", bufferLength , fOffset);
fOffset += bufferLength;
fBytesWrite += bufferLength;
#ifdef WIN32
SetFileBytesWritten(GetFileBytesWritten() + bufferLength);
#else
fgBytesWrite += bufferLength;
#endif
return kFALSE;
}
void TXNetFile::Init(Bool_t create)
{
if (fInitDone) {
if (gDebug > 1)
Info("Init","TFile::Init already called once");
return;
}
if (fIsRootd) {
if (gDebug > 1)
Info("Init","rootd: calling directly TFile::Init");
return TNetFile::Init(create);
}
if (fClient) {
XrdSysMutexHelper m(fInitMtx);
if (fClient->IsOpen_wait()) {
if (gMonitoringWriter)
gMonitoringWriter->SendFileOpenProgress(this, fOpenPhases, "rootinit", kFALSE);
bool usecachesave = fClient->UseCache(0);
TFile::Init(create);
fD = -2;
fClient->UseCache(usecachesave);
if (gMonitoringWriter)
gMonitoringWriter->SendFileOpenProgress(this, fOpenPhases, "endopen", kTRUE);
fEndpointUrl = fClient->GetClientConn()->GetCurrentUrl().GetUrl().c_str();
if (fEndpointUrl.GetPort() != fUrl.GetPort() ||
strcmp(fEndpointUrl.GetHostFQDN(), fUrl.GetHostFQDN()))
SetBit(TFile::kRedirected);
} else {
if (gDebug > 0)
Info("Init","open request failed!");
SafeDelete(fClient);
MakeZombie();
gDirectory = gROOT;
}
}
}
Bool_t TXNetFile::IsOpen() const
{
if (fIsRootd) {
if (gDebug > 1)
Info("IsOpen","Calling TNetFile::IsOpen");
return TNetFile::IsOpen();
}
if (!fClient)
return kFALSE;
return ((fClient && fInitDone) ? fClient->IsOpen() : kFALSE);
}
TFile::EAsyncOpenStatus TXNetFile::GetAsyncOpenStatus()
{
if (fAsyncOpenStatus != TFile::kAOSNotAsync) {
if (fClient->IsOpen_inprogress()) {
return TFile::kAOSInProgress;
} else {
if (fClient->IsOpen())
return TFile::kAOSSuccess;
else
return TFile::kAOSFailure;
}
}
return TFile::kAOSNotAsync;
}
Int_t TXNetFile::ReOpen(const Option_t *Mode)
{
if (fIsRootd) {
if (gDebug > 1)
Info("ReOpen","Calling TNetFile::ReOpen");
return TNetFile::ReOpen(Mode);
}
return TFile::ReOpen(Mode);
}
void TXNetFile::Close(const Option_t *opt)
{
if (fIsRootd) {
if (gDebug > 1)
Info("Close","Calling TNetFile::Close");
TNetFile::Close(opt);
return;
}
if (!fClient) return;
TFile::Close(opt);
fIsRootd = kFALSE;
if (IsOpen())
fClient->Close();
SafeDelete(fClient);
fD = -1;
}
void TXNetFile::Flush()
{
if (IsZombie()) {
Error("Flush", "Flush is not possible because object is"
" in 'zombie' state");
return;
}
if (!fWritable) {
if (gDebug > 1)
Info("Flush", "file not writable - do nothing");
return;
}
if (fIsRootd) {
if (gDebug > 1)
Info("Flush","Calling TNetFile::Flush");
TNetFile::Flush();
return;
}
if (!IsOpen()) {
Error("Flush","The remote file is not open");
return;
}
FlushWriteCache();
fClient->Sync();
if (gDebug > 1)
Info("Flush", "XrdClient::Sync called.");
}
Int_t TXNetFile::SysStat(Int_t fd, Long_t *id, Long64_t *size, Long_t *flags,
Long_t *modtime)
{
if (IsZombie()) {
Error("SysStat", "SysStat is not possible because object is"
" in 'zombie' state");
*size = 0;
return 1;
}
if (fIsRootd) {
if (gDebug > 1)
Info("SysStat", "calling TNetFile::SysStat");
return TNetFile::SysStat(fd, id, size, flags, modtime);
}
if (!IsOpen()) {
if (gDebug > 1)
Info("SysStat", "could not stat remote file, file not open");
*id = -1;
return 1;
}
struct XrdClientStatInfo stinfo;
if (fClient->Stat(&stinfo)) {
*id = (Long_t)(stinfo.id);
*size = (Long64_t)(stinfo.size);
*flags = (Long_t)(stinfo.flags);
*modtime = (Long_t)(stinfo.modtime);
if (gDebug > 1)
Info("SysStat", "got stats = %ld %lld %ld %ld",
*id, *size, *flags, *modtime);
} else {
if (gDebug > 1)
Info("SysStat", "could not stat remote file");
*id = -1;
return 1;
}
return 0;
}
Int_t TXNetFile::SysClose(Int_t fd)
{
if (IsZombie()) {
Error("SysClose", "SysClose is not possible because object is"
" in 'zombie' state");
return 0;
}
if (fIsRootd) {
if (gDebug > 1)
Info("SysClose","Calling TNetFile::SysClose");
return TNetFile::SysClose(fd);
}
if (IsOpen())
fClient->Close();
return 0;
}
Int_t TXNetFile::SysOpen(const char* pathname, Int_t flags, UInt_t mode)
{
if (fIsRootd) {
if (gDebug > 1)
Info("SysOpen", "Calling TNetFile::SysOpen");
return TNetFile::SysOpen(pathname, flags, mode);
}
if (!fClient) {
CreateXClient(fUrl.GetUrl(), fOption, fNetopt, kFALSE);
} else {
Open(fOption.Data(), kFALSE);
}
if (!IsOpen())
return -1;
return -2;
}
void TXNetFile::SetEnv()
{
TString allowRE = gEnv->GetValue("XNet.RedirDomainAllowRE", "");
if (allowRE.Length() > 0)
EnvPutString(NAME_REDIRDOMAINALLOW_RE, allowRE.Data());
TString denyRE = gEnv->GetValue("XNet.RedirDomainDenyRE", "");
if (denyRE.Length() > 0)
EnvPutString(NAME_REDIRDOMAINDENY_RE, denyRE.Data());
TString allowCO = gEnv->GetValue("XNet.ConnectDomainAllowRE", "");
if (allowCO.Length() > 0)
EnvPutString(NAME_CONNECTDOMAINALLOW_RE, allowCO.Data());
TString denyCO = gEnv->GetValue("XNet.ConnectDomainDenyRE", "");
if (denyCO.Length() > 0)
EnvPutString(NAME_CONNECTDOMAINDENY_RE, denyCO.Data());
Int_t connTO = gEnv->GetValue("XNet.ConnectTimeout",
DFLT_CONNECTTIMEOUT);
EnvPutInt(NAME_CONNECTTIMEOUT, connTO);
Int_t recoTO = gEnv->GetValue("XNet.ReconnectTimeout",
DFLT_RECONNECTTIMEOUT);
EnvPutInt(NAME_RECONNECTTIMEOUT, recoTO);
Int_t requTO = gEnv->GetValue("XNet.RequestTimeout",
DFLT_REQUESTTIMEOUT);
EnvPutInt(NAME_REQUESTTIMEOUT, requTO);
Int_t maxRedir = gEnv->GetValue("XNet.MaxRedirectCount",
DFLT_MAXREDIRECTCOUNT);
EnvPutInt(NAME_MAXREDIRECTCOUNT, maxRedir);
Int_t garbCollTh = gEnv->GetValue("XNet.StartGarbageCollectorThread",
DFLT_STARTGARBAGECOLLECTORTHREAD);
EnvPutInt(NAME_STARTGARBAGECOLLECTORTHREAD, garbCollTh);
Int_t rAheadsiz = gEnv->GetValue("XNet.ReadAheadSize",
DFLT_READAHEADSIZE);
EnvPutInt(NAME_READAHEADSIZE, rAheadsiz);
Int_t rCachesiz = gEnv->GetValue("XNet.ReadCacheSize",
DFLT_READCACHESIZE);
EnvPutInt(NAME_READCACHESIZE, rCachesiz);
Int_t maxRetries = gEnv->GetValue("XNet.FirstConnectMaxCnt",
DFLT_FIRSTCONNECTMAXCNT);
EnvPutInt(NAME_FIRSTCONNECTMAXCNT, maxRetries);
Int_t parStreamsCnt = gEnv->GetValue("XNet.ParStreamsPerPhyConn",
DFLT_MULTISTREAMCNT);
EnvPutInt(NAME_MULTISTREAMCNT, parStreamsCnt);
fgRootdBC = gEnv->GetValue("XNet.RootdFallback", 1);
EnvPutInt(NAME_KEEPSOCKOPENIFNOTXRD, fgRootdBC);
TString socks4Host = gEnv->GetValue("XNet.SOCKS4Host","");
Int_t socks4Port = gEnv->GetValue("XNet.SOCKS4Port",-1);
if (socks4Port > 0) {
if (socks4Host.IsNull())
socks4Host = "127.0.0.1";
EnvPutString(NAME_SOCKS4HOST, socks4Host.Data());
EnvPutInt(NAME_SOCKS4PORT, socks4Port);
}
TString autolog = gEnv->GetValue("XSec.Pwd.AutoLogin","1");
if (autolog.Length() > 0)
gSystem->Setenv("XrdSecPWDAUTOLOG",autolog.Data());
TString netrc;
netrc.Form("%s/.rootnetrc",gSystem->HomeDirectory());
gSystem->Setenv("XrdSecNETRC", netrc.Data());
TString alogfile = gEnv->GetValue("XSec.Pwd.ALogFile","");
if (alogfile.Length() > 0)
gSystem->Setenv("XrdSecPWDALOGFILE",alogfile.Data());
TString verisrv = gEnv->GetValue("XSec.Pwd.VerifySrv","1");
if (verisrv.Length() > 0)
gSystem->Setenv("XrdSecPWDVERIFYSRV",verisrv.Data());
TString srvpuk = gEnv->GetValue("XSec.Pwd.ServerPuk","");
if (srvpuk.Length() > 0)
gSystem->Setenv("XrdSecPWDSRVPUK",srvpuk.Data());
TString cadir = gEnv->GetValue("XSec.GSI.CAdir","");
if (cadir.Length() > 0)
gSystem->Setenv("XrdSecGSICADIR",cadir.Data());
TString crldir = gEnv->GetValue("XSec.GSI.CRLdir","");
if (crldir.Length() > 0)
gSystem->Setenv("XrdSecGSICRLDIR",crldir.Data());
TString crlext = gEnv->GetValue("XSec.GSI.CRLextension","");
if (crlext.Length() > 0)
gSystem->Setenv("XrdSecGSICRLEXT",crlext.Data());
TString ucert = gEnv->GetValue("XSec.GSI.UserCert","");
if (ucert.Length() > 0)
gSystem->Setenv("XrdSecGSIUSERCERT",ucert.Data());
TString ukey = gEnv->GetValue("XSec.GSI.UserKey","");
if (ukey.Length() > 0)
gSystem->Setenv("XrdSecGSIUSERKEY",ukey.Data());
TString upxy = gEnv->GetValue("XSec.GSI.UserProxy","");
if (upxy.Length() > 0)
gSystem->Setenv("XrdSecGSIUSERPROXY",upxy.Data());
TString valid = gEnv->GetValue("XSec.GSI.ProxyValid","");
if (valid.Length() > 0)
gSystem->Setenv("XrdSecGSIPROXYVALID",valid.Data());
TString deplen = gEnv->GetValue("XSec.GSI.ProxyForward","0");
if (deplen.Length() > 0)
gSystem->Setenv("XrdSecGSIPROXYDEPLEN",deplen.Data());
TString pxybits = gEnv->GetValue("XSec.GSI.ProxyKeyBits","");
if (pxybits.Length() > 0)
gSystem->Setenv("XrdSecGSIPROXYKEYBITS",pxybits.Data());
TString crlcheck = gEnv->GetValue("XSec.GSI.CheckCRL","1");
if (crlcheck.Length() > 0)
gSystem->Setenv("XrdSecGSICRLCHECK",crlcheck.Data());
TString delegpxy = gEnv->GetValue("XSec.GSI.DelegProxy","0");
if (delegpxy.Length() > 0)
gSystem->Setenv("XrdSecGSIDELEGPROXY",delegpxy.Data());
TString signpxy = gEnv->GetValue("XSec.GSI.SignProxy","1");
if (signpxy.Length() > 0)
gSystem->Setenv("XrdSecGSISIGNPROXY",signpxy.Data());
gSystem->IgnoreSignal(kSigPipe);
}
void TXNetFile::SynchronizeCacheSize()
{
fClient->UseCache(TRUE);
#ifndef OLDXRDLOCATE
Int_t size;
Long64_t bytessubmitted, byteshit, misscount, readreqcnt;
Float_t missrate, bytesusefulness;
int newbsz = -1;
if (fClient && fClient->GetCacheInfo(size, bytessubmitted,
byteshit, misscount,
missrate, readreqcnt,
bytesusefulness) ) {
newbsz = GetCacheRead()->GetBufferSize() / 2 * 3;
newbsz = TMath::Max(newbsz, size);
}
fClient->SetCacheParameters(newbsz, 0, XrdClientReadCache::kRmBlk_FIFO);
#else
EnvPutInt(NAME_READAHEADSIZE, 0);
#endif
}
void TXNetFile::ResetCache()
{
if (fClient)
fClient->RemoveAllDataFromCache();
}
Int_t TXNetFile::GetBytesToPrefetch() const
{
#ifndef OLDXRDLOCATE
Int_t size;
Long64_t bytessubmitted, byteshit, misscount, readreqcnt;
Float_t missrate, bytesusefulness;
Int_t bytes = 0;
if (fClient && fClient->GetCacheInfo(size, bytessubmitted,
byteshit, misscount,
missrate, readreqcnt,
bytesusefulness) )
bytes = size;
#else
Int_t bytes = gEnv->GetValue("XNet.ReadCacheSize", 0)/2;
#endif
return ((bytes < 0) ? 0 : bytes);
}
void TXNetFile::Print(Option_t *option) const
{
#ifndef OLDXRDLOCATE
Printf("TXNetFile caching information:\n");
int size;
long long bytessubmitted, byteshit, misscount, readreqcnt;
float missrate, bytesusefulness;
if ( fClient && fClient->GetCacheInfo(size, bytessubmitted,
byteshit, misscount,
missrate, readreqcnt,
bytesusefulness) ) {
Printf(" Max size: %ld\n", size);
Printf(" Bytes submitted: %lld\n", bytessubmitted);
Printf(" Bytes hit (estimation): %lld\n", byteshit);
Printf(" Miss count: %lld\n", misscount);
Printf(" Miss rate: %f\n", missrate);
Printf(" Read requests count: %lld\n", readreqcnt);
Printf(" Bytes usefulness: %f\n\n", bytesusefulness);
}
else
Printf(" -- No Xrd client instance allocated --\n\n");
#endif
TFile::Print(option);
}
Last change: Wed Oct 8 15:35:12 2008
Last generated: 2008-10-08 15:35
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.