ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TNetFile.cxx
Go to the documentation of this file.
1 // @(#)root/net:$Id$
2 // Author: Fons Rademakers 14/08/97
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 //////////////////////////////////////////////////////////////////////////
13 // //
14 // TNetFile //
15 // //
16 // A TNetFile is like a normal TFile except that it reads and writes //
17 // its data via a rootd server (for more on the rootd daemon see the //
18 // source files root/rootd/src/*.cxx). TNetFile file names are in //
19 // standard URL format with protocol "root" or "roots". The following //
20 // are valid TNetFile URL's: //
21 // //
22 // roots://hpsalo/files/aap.root //
23 // root://hpbrun.cern.ch/root/hsimple.root //
24 // root://pcna49a:5151/~na49/data/run821.root //
25 // root://pcna49d.cern.ch:5050//v1/data/run810.root //
26 // //
27 // The only difference with the well known httpd URL's is that the root //
28 // of the remote file tree is the user's home directory. Therefore an //
29 // absolute pathname requires a // after the host or port specifier //
30 // (see last example). Further the expansion of the standard shell //
31 // characters, like ~, $, .., are handled as expected. //
32 // TNetFile (actually TUrl) uses 1094 as default port for rootd. //
33 // //
34 // Connecting to a rootd requires the remote user id and password. //
35 // TNetFile allows three ways for you to provide your login: //
36 // 1) Setting it globally via the static functions: //
37 // TAuthenticate::SetGlobalUser() and //
38 // TAuthenticate::SetGlobalPasswd() //
39 // 2) Getting it from the ~/.netrc file (same file as used by ftp) //
40 // 3) Command line prompt //
41 // The different methods will be tried in the order given above. //
42 // On machines with AFS rootd will authenticate using AFS (if it was //
43 // compiled with AFS support). //
44 // //
45 // If the protocol is specified as "roots" a secure authetication //
46 // method will be used. The secure method uses the SRP, Secure Remote //
47 // Passwords, package. SRP uses a so called "asymmetric key exchange //
48 // protocol" in which no passwords are ever send over the wire. This //
49 // protocol is safe against all known security attacks. For more see: //
50 // Begin_Html <a href=http://root.cern.ch/root/NetFile.html>NetFile</a> //
51 // End_Html //
52 // If the protocol is specified as "rootk" kerberos5 will be used for //
53 // authentication. //
54 // //
55 // The rootd daemon lives in the directory $ROOTSYS/bin. It can be //
56 // started either via inetd or by hand from the command line (no need //
57 // to be super user). For more info about rootd see the web page: //
58 // Begin_Html <a href=http://root.cern.ch/root/NetFile.html>NetFile</a> //
59 // End_Html //
60 // //
61 //////////////////////////////////////////////////////////////////////////
62 
63 #include <errno.h>
64 
65 #include "Bytes.h"
66 #include "NetErrors.h"
67 #include "TApplication.h"
68 #include "TEnv.h"
69 #include "TNetFile.h"
70 #include "TPSocket.h"
71 #include "TROOT.h"
72 #include "TSysEvtHandler.h"
73 #include "TSystem.h"
74 #include "TTimeStamp.h"
75 #include "TVirtualPerfStats.h"
76 
77 // fgClientProtocol is now in TAuthenticate
78 
81 
82 ////////////////////////////////////////////////////////////////////////////////
83 /// Create a TNetFile object. This is actually done inside Create(), so
84 /// for a description of the options and other arguments see Create().
85 /// Normally a TNetFile is created via TFile::Open().
86 
87 TNetFile::TNetFile(const char *url, Option_t *option, const char *ftitle,
88  Int_t compress, Int_t netopt)
89  : TFile(url, "NET", ftitle, compress), fEndpointUrl(url)
90 {
91  fSocket = 0;
92  Create(url, option, netopt);
93 }
94 
95 ////////////////////////////////////////////////////////////////////////////////
96 /// Create a TNetFile object. To be used by derived classes, that need
97 /// to initialize the TFile base class but not open a connection at this
98 /// moment.
99 
100 TNetFile::TNetFile(const char *url, const char *ftitle, Int_t compress, Bool_t)
101  : TFile(url, "NET", ftitle, compress), fEndpointUrl(url)
102 {
103  fSocket = 0;
104  fProtocol = 0;
105  fErrorCode = 0;
106  fNetopt = 0;
107 }
108 
109 ////////////////////////////////////////////////////////////////////////////////
110 /// TNetFile dtor. Send close message and close socket.
111 
113 {
114  Close();
115 }
116 
117 ////////////////////////////////////////////////////////////////////////////////
118 /// Open a remote file. Requires fOption to be set correctly.
119 
120 Int_t TNetFile::SysOpen(const char * /*file*/, Int_t /*flags*/, UInt_t /*mode*/)
121 {
122  if (!fSocket) {
123 
125  if (!fSocket) return -1;
126 
127  } else {
128 
129  if (fProtocol > 15) {
130  fSocket->Send(Form("%s %s", fUrl.GetFile(), ToLower(fOption).Data()),
131  kROOTD_OPEN);
132  } else {
133  // Old daemon versions expect an additional slash at beginning
134  fSocket->Send(Form("/%s %s", fUrl.GetFile(), ToLower(fOption).Data()),
135  kROOTD_OPEN);
136  }
137 
138  EMessageTypes kind;
139  int stat;
140  Recv(stat, kind);
141 
142  if (kind == kROOTD_ERR) {
143  PrintError("SysOpen", stat);
144  return -1;
145  }
146  }
147 
148  // This means ok for net files
149  return -2; // set as fD in ReOpen
150 }
151 
152 ////////////////////////////////////////////////////////////////////////////////
153 /// Close currently open file.
154 
156 {
157  if (fSocket)
159 
160  return 0;
161 }
162 
163 ////////////////////////////////////////////////////////////////////////////////
164 /// Return file stat information. The interface and return value is
165 /// identical to TSystem::GetPathInfo().
166 
167 Int_t TNetFile::SysStat(Int_t, Long_t *id, Long64_t *size, Long_t *flags, Long_t *modtime)
168 {
169  if (fProtocol < 3) return 1;
170 
171  if (!fSocket) return 1;
172 
174 
175  char msg[1024];
176  Int_t kind;
177  fSocket->Recv(msg, sizeof(msg), kind);
178 
179  Int_t mode, uid, gid, islink;
180  Long_t dev, ino;
181 
182  if (fProtocol > 12) {
183 #ifdef R__WIN32
184  sscanf(msg, "%ld %ld %d %d %d %I64d %ld %d", &dev, &ino, &mode,
185  &uid, &gid, size, modtime, &islink);
186 #else
187  sscanf(msg, "%ld %ld %d %d %d %lld %ld %d", &dev, &ino, &mode,
188  &uid, &gid, size, modtime, &islink);
189 #endif
190  if (dev == -1)
191  return 1;
192  if (id)
193  *id = (dev << 24) + ino;
194  if (flags) {
195  *flags = 0;
196  if (mode & (kS_IXUSR|kS_IXGRP|kS_IXOTH))
197  *flags |= 1;
198  if (R_ISDIR(mode))
199  *flags |= 2;
200  if (!R_ISREG(mode) && !R_ISDIR(mode))
201  *flags |= 4;
202  }
203  } else {
204 #ifdef R__WIN32
205  sscanf(msg, "%ld %I64d %ld %ld", id, size, flags, modtime);
206 #else
207  sscanf(msg, "%ld %lld %ld %ld", id, size, flags, modtime);
208 #endif
209  if (*id == -1)
210  return 1;
211  }
212 
213  return 0;
214 }
215 
216 ////////////////////////////////////////////////////////////////////////////////
217 /// Close remote file.
218 
220 {
221  if (!fSocket) return;
222 
223  TFile::Close(opt);
224 
225  if (fProtocol > 6)
227 
229 
230  fD = -1; // so TFile::IsOpen() returns false when in TFile::~TFile
231 }
232 
233 ////////////////////////////////////////////////////////////////////////////////
234 /// Flush file to disk.
235 
237 {
238  FlushWriteCache();
239 
240  if (fSocket && fWritable)
242 }
243 
244 ////////////////////////////////////////////////////////////////////////////////
245 /// Initialize a TNetFile object.
246 
247 void TNetFile::Init(Bool_t create)
248 {
249  Seek(0);
250 
251  TFile::Init(create);
252  fD = -2; // so TFile::IsOpen() returns true when in TFile::~TFile
253 }
254 
255 ////////////////////////////////////////////////////////////////////////////////
256 /// Retruns kTRUE if file is open, kFALSE otherwise.
257 
259 {
260  return fSocket == 0 ? kFALSE : kTRUE;
261 }
262 
263 ////////////////////////////////////////////////////////////////////////////////
264 /// Print some info about the net file.
265 
267 {
268  const char *fname = fUrl.GetFile();
269  Printf("URL: %s", ((TUrl*)&fUrl)->GetUrl());
270  Printf("Remote file: %s", &fname[1]);
271  Printf("Remote user: %s", fUser.Data());
272  Printf("Title: %s", fTitle.Data());
273  Printf("Option: %s", fOption.Data());
274  Printf("Bytes written: %lld", fBytesWrite);
275  Printf("Bytes read: %lld", fBytesRead);
276 }
277 
278 ////////////////////////////////////////////////////////////////////////////////
279 /// Print error string depending on error code.
280 
281 void TNetFile::PrintError(const char *where, Int_t err)
282 {
283  fErrorCode = err;
284  Error(where, "%s", gRootdErrStr[err]);
285 }
286 
287 ////////////////////////////////////////////////////////////////////////////////
288 /// Reopen a file with a different access mode, like from READ to
289 /// UPDATE or from NEW, CREATE, RECREATE, UPDATE to READ. Thus the
290 /// mode argument can be either "READ" or "UPDATE". The method returns
291 /// 0 in case the mode was successfully modified, 1 in case the mode
292 /// did not change (was already as requested or wrong input arguments)
293 /// and -1 in case of failure, in which case the file cannot be used
294 /// anymore.
295 
297 {
298  if (fProtocol < 7) {
299  Error("ReOpen", "operation not supported by remote rootd (protocol = %d)",
300  fProtocol);
301  return 1;
302  }
303 
304  return TFile::ReOpen(mode);
305 }
306 
307 ////////////////////////////////////////////////////////////////////////////////
308 /// Read specified byte range from remote file via rootd daemon.
309 /// Returns kTRUE in case of error.
310 
312 {
313  if (!fSocket) return kTRUE;
314  if (len == 0)
315  return kFALSE;
316 
317  Bool_t result = kFALSE;
318 
319  Int_t st;
320  if ((st = ReadBufferViaCache(buf, len))) {
321  if (st == 2)
322  return kTRUE;
323  return kFALSE;
324  }
325 
328 
329  Double_t start = 0;
330  if (gPerfStats) start = TTimeStamp();
331 
332  if (fSocket->Send(Form("%lld %d", fOffset, len), kROOTD_GET) < 0) {
333  Error("ReadBuffer", "error sending kROOTD_GET command");
334  result = kTRUE;
335  goto end;
336  }
337 
338  Int_t stat, n;
339  EMessageTypes kind;
340 
341  fErrorCode = -1;
342  if (Recv(stat, kind) < 0 || kind == kROOTD_ERR) {
343  PrintError("ReadBuffer", stat);
344  result = kTRUE;
345  goto end;
346  }
347 
348  while ((n = fSocket->RecvRaw(buf, len)) < 0 && TSystem::GetErrno() == EINTR)
350 
351  if (n != len) {
352  Error("ReadBuffer", "error receiving buffer of length %d, got %d", len, n);
353  result = kTRUE;
354  goto end;
355  }
356 
357  fOffset += len;
358 
359  fBytesRead += len;
360  fReadCalls++;
361 #ifdef R__WIN32
364 #else
365  fgBytesRead += len;
366  fgReadCalls++;
367 #endif
368 
369 end:
370 
371  if (gPerfStats)
372  gPerfStats->FileReadEvent(this, len, start);
373 
376 
377  return result;
378 }
379 
380 ////////////////////////////////////////////////////////////////////////////////
381 /// Read specified byte range from remote file via rootd daemon.
382 /// Returns kTRUE in case of error.
383 
385 {
386  SetOffset(pos);
387  return ReadBuffer(buf, len);
388 }
389 
390 ////////////////////////////////////////////////////////////////////////////////
391 /// Read a list of buffers given in pos[] and len[] and return it in a single
392 /// buffer.
393 /// Returns kTRUE in case of error.
394 
395 Bool_t TNetFile::ReadBuffers(char *buf, Long64_t *pos, Int_t *len, Int_t nbuf)
396 {
397  if (!fSocket) return kTRUE;
398 
399  // If it's an old version of the protocol try the default TFile::ReadBuffers
400  if (fProtocol < 17)
401  return TFile::ReadBuffers(buf, pos, len, nbuf);
402 
403  Int_t stat;
404  Int_t blockSize = 262144; //Let's say we transfer 256KB at the time
405  Bool_t result = kFALSE;
406  EMessageTypes kind;
407  TString data_buf; // buf to put the info
408 
411 
412  Double_t start = 0;
413  if (gPerfStats) start = TTimeStamp();
414 
415  // Make the string with a list of offsets and lengths
416  Long64_t total_len = 0;
417  Long64_t actual_pos;
418  for(Int_t i = 0; i < nbuf; i++) {
419  data_buf += pos[i] + fArchiveOffset;
420  data_buf += "-";
421  data_buf += len[i];
422  data_buf += "/";
423  total_len += len[i];
424  }
425 
426  // Send the command with the length of the info and number of buffers
427  if (fSocket->Send(Form("%d %d %d", nbuf, data_buf.Length(), blockSize),
428  kROOTD_GETS) < 0) {
429  Error("ReadBuffers", "error sending kROOTD_GETS command");
430  result = kTRUE;
431  goto end;
432  }
433  // Send buffer with the list of offsets and lengths
434  if (fSocket->SendRaw(data_buf, data_buf.Length()) < 0) {
435  Error("ReadBuffers", "error sending buffer");
436  result = kTRUE;
437  goto end;
438  }
439 
440  fErrorCode = -1;
441  if (Recv(stat, kind) < 0 || kind == kROOTD_ERR) {
442  PrintError("ReadBuffers", stat);
443  result = kTRUE;
444  goto end;
445  }
446 
447  actual_pos = 0;
448  while (actual_pos < total_len) {
449  Long64_t left = total_len - actual_pos;
450  if (left > blockSize)
451  left = blockSize;
452 
453  Int_t n;
454  while ((n = fSocket->RecvRaw(buf + actual_pos, Int_t(left))) < 0 &&
455  TSystem::GetErrno() == EINTR)
457 
458  if (n != Int_t(left)) {
459  Error("GetBuffers", "error receiving buffer of length %d, got %d",
460  Int_t(left), n);
461  result = kTRUE ;
462  goto end;
463  }
464  actual_pos += left;
465  }
466 
467  fBytesRead += total_len;
468  fReadCalls++;
469 #ifdef R__WIN32
470  SetFileBytesRead(GetFileBytesRead() + total_len);
472 #else
473  fgBytesRead += total_len;
474  fgReadCalls++;
475 #endif
476 
477 end:
478 
479  if (gPerfStats)
480  gPerfStats->FileReadEvent(this, total_len, start);
481 
484 
485  // If found problems try the generic implementation
486  if (result) {
487  if (gDebug > 0)
488  Info("ReadBuffers", "Couldnt use the specific implementation, calling TFile::ReadBuffers");
489  return TFile::ReadBuffers(buf, pos, len, nbuf);
490  }
491 
492  return result;
493 }
494 
495 ////////////////////////////////////////////////////////////////////////////////
496 /// Write specified byte range to remote file via rootd daemon.
497 /// Returns kTRUE in case of error.
498 
499 Bool_t TNetFile::WriteBuffer(const char *buf, Int_t len)
500 {
501  if (!fSocket || !fWritable) return kTRUE;
502 
503  Bool_t result = kFALSE;
504 
505  Int_t st;
506  if ((st = WriteBufferViaCache(buf, len))) {
507  if (st == 2)
508  return kTRUE;
509  return kFALSE;
510  }
511 
513 
514  if (fSocket->Send(Form("%lld %d", fOffset, len), kROOTD_PUT) < 0) {
516  Error("WriteBuffer", "error sending kROOTD_PUT command");
517  result = kTRUE;
518  goto end;
519  }
520  if (fSocket->SendRaw(buf, len) < 0) {
522  Error("WriteBuffer", "error sending buffer");
523  result = kTRUE;
524  goto end;
525  }
526 
527  Int_t stat;
528  EMessageTypes kind;
529 
530  fErrorCode = -1;
531  if (Recv(stat, kind) < 0 || kind == kROOTD_ERR) {
533  PrintError("WriteBuffer", stat);
534  result = kTRUE;
535  goto end;
536  }
537 
538  fOffset += len;
539 
540  fBytesWrite += len;
541 #ifdef R__WIN32
543 #else
544  fgBytesWrite += len;
545 #endif
546 
547 end:
549 
550  return result;
551 }
552 
553 ////////////////////////////////////////////////////////////////////////////////
554 /// Return status from rootd server and message kind. Returns -1 in
555 /// case of error otherwise 8 (sizeof 2 words, status and kind).
556 
558 {
559  kind = kROOTD_ERR;
560  status = 0;
561 
562  if (!fSocket) return -1;
563 
564  Int_t what;
565  Int_t n = fSocket->Recv(status, what);
566  kind = (EMessageTypes) what;
567  return n;
568 }
569 
570 ////////////////////////////////////////////////////////////////////////////////
571 /// Set position from where to start reading.
572 
574 {
575  SetOffset(offset, pos);
576 }
577 
578 ////////////////////////////////////////////////////////////////////////////////
579 /// Connect to remote rootd server.
580 
582  Int_t tcpwindowsize, Bool_t forceOpen,
583  Bool_t forceRead)
584 {
585  TString fn = fUrl.GetFile();
586 
587  // Create Authenticated socket
588  Int_t sSize = netopt < -1 ? -netopt : 1;
589  TString url(fUrl.GetProtocol());
590  if (url.Contains("root")) {
591  url.Insert(4,"dp");
592  } else {
593  url = "rootdp";
594  }
595  url += TString(Form("://%s@%s:%d",
596  fUrl.GetUser(), fUrl.GetHost(), fUrl.GetPort()));
597  fSocket = TSocket::CreateAuthSocket(url, sSize, tcpwindowsize, fSocket, stat);
598  if (!fSocket || (fSocket && !fSocket->IsAuthenticated())) {
599  if (sSize > 1)
600  Error("TNetFile", "can't open %d-stream connection to rootd on "
601  "host %s at port %d", sSize, fUrl.GetHost(), fUrl.GetPort());
602  else
603  Error("TNetFile", "can't open connection to rootd on "
604  "host %s at port %d", fUrl.GetHost(), fUrl.GetPort());
605  *kind = kROOTD_ERR;
606  goto zombie;
607  }
608 
609  // Check if rootd supports new options
611  if (forceRead && fProtocol < 5) {
612  Warning("ConnectServer", "rootd does not support \"+read\" option");
613  forceRead = kFALSE;
614  }
615 
616  // Open the file
617  if (fProtocol < 16)
618  // For backward compatibility we need to add a '/' at the beginning
619  fn.Insert(0,"/");
620  if (forceOpen)
621  fSocket->Send(Form("%s %s", fn.Data(),
622  ToLower("f"+fOption).Data()), kROOTD_OPEN);
623  else if (forceRead)
624  fSocket->Send(Form("%s %s", fn.Data(), "+read"), kROOTD_OPEN);
625  else
626  fSocket->Send(Form("%s %s", fn.Data(),
628 
629  EMessageTypes tmpkind;
630  int tmpstat;
631  Recv(tmpstat, tmpkind);
632  *stat = tmpstat;
633  *kind = tmpkind;
634 
635  return;
636 
637 zombie:
638  // error in file opening occured, make this object a zombie
639  MakeZombie();
641  gDirectory = gROOT;
642 }
643 
644 ////////////////////////////////////////////////////////////////////////////////
645 /// Create a NetFile object. A net file is the same as a TFile
646 /// except that it is being accessed via a rootd server. The url
647 /// argument must be of the form: root[s|k]://host.dom.ain/file.root.
648 /// When protocol is "roots" try using SRP authentication.
649 /// When protocol is "rootk" try using kerberos5 authentication.
650 /// If the file specified in the URL does not exist, is not accessable
651 /// or can not be created the kZombie bit will be set in the TNetFile
652 /// object. Use IsZombie() to see if the file is accessable.
653 /// If the remote daemon thinks the file is still connected, while you are
654 /// sure this is not the case you can force open the file by preceding the
655 /// option argument with an "-", e.g.: "-recreate". Do this only
656 /// in cases when you are very sure nobody else is using the file.
657 /// To bypass the writelock on a file, to allow the reading of a file
658 /// that is being written by another process, explicitly specify the
659 /// "+read" option ("read" being the default option).
660 /// The netopt argument can be used to specify the size of the tcp window in
661 /// bytes (for more info see: http://www.psc.edu/networking/perf_tune.html).
662 /// The default and minimum tcp window size is 65535 bytes.
663 /// If netopt < -1 then |netopt| is the number of parallel sockets that will
664 /// be used to connect to rootd. This option should be used on fat pipes
665 /// (i.e. high bandwidth, high latency links). The ideal number of parallel
666 /// sockets depends on the bandwidth*delay product. Generally 5-7 is a good
667 /// number.
668 /// For a description of the option and other arguments see the TFile ctor.
669 /// The preferred interface to this constructor is via TFile::Open().
670 
671 void TNetFile::Create(const char * /*url*/, Option_t *option, Int_t netopt)
672 {
673  Int_t tcpwindowsize = 65535;
674 
675  fErrorCode = -1;
676  fNetopt = netopt;
677  fOption = option;
678 
679  Bool_t forceOpen = kFALSE;
680  if (option[0] == '-') {
681  fOption = &option[1];
682  forceOpen = kTRUE;
683  }
684  // accept 'f', like 'frecreate' still for backward compatibility
685  if (option[0] == 'F' || option[0] == 'f') {
686  fOption = &option[1];
687  forceOpen = kTRUE;
688  }
689 
690  Bool_t forceRead = kFALSE;
691  if (!strcasecmp(option, "+read")) {
692  fOption = &option[1];
693  forceRead = kTRUE;
694  }
695 
696  fOption.ToUpper();
697 
698  if (fOption == "NEW")
699  fOption = "CREATE";
700 
701  Bool_t create = (fOption == "CREATE") ? kTRUE : kFALSE;
702  Bool_t recreate = (fOption == "RECREATE") ? kTRUE : kFALSE;
703  Bool_t update = (fOption == "UPDATE") ? kTRUE : kFALSE;
704  Bool_t read = (fOption == "READ") ? kTRUE : kFALSE;
705  if (!create && !recreate && !update && !read) {
706  read = kTRUE;
707  fOption = "READ";
708  }
709 
710  if (!fUrl.IsValid()) {
711  Error("Create", "invalid URL specified: %s", fUrl.GetUrl());
712  goto zombie;
713  }
714 
715  if (netopt > tcpwindowsize)
716  tcpwindowsize = netopt;
717 
718  // Open connection to remote rootd server
719  EMessageTypes kind;
720  Int_t stat;
721  ConnectServer(&stat, &kind, netopt, tcpwindowsize, forceOpen, forceRead);
722  if (gDebug > 2) Info("Create", "got from host %d %d", stat, kind);
723 
724  if (kind == kROOTD_ERR) {
725  PrintError("Create", stat);
726  Error("Create", "failing on file %s", fUrl.GetUrl());
727  goto zombie;
728  }
729 
730  if (recreate) {
731  recreate = kFALSE;
732  create = kTRUE;
733  fOption = "CREATE";
734  }
735 
736  if (update && stat > 1) {
737  update = kFALSE;
738  create = kTRUE;
739  stat = 1;
740  }
741 
742  if (stat == 1)
743  fWritable = kTRUE;
744  else
745  fWritable = kFALSE;
746 
747  Init(create);
748  return;
749 
750 zombie:
751  // error in file opening occured, make this object a zombie
752  MakeZombie();
754  gDirectory = gROOT;
755 }
756 
757 ////////////////////////////////////////////////////////////////////////////////
758 /// Create a NetFile object using an existing connection (socket s).
759 /// Provided for use in TXNetFile.
760 /// See:
761 /// TNetFile::Create(const char *url, Option_t *option, Int_t netopt)
762 /// for details about the arguments.
763 
764 void TNetFile::Create(TSocket *s, Option_t *option, Int_t netopt)
765 {
766  // Import socket
767  fSocket = s;
768 
769  // Create the connection
770  Create(s->GetUrl(), option, netopt);
771 }
772 
773 ////////////////////////////////////////////////////////////////////////////////
774 /// Return kTRUE if 'url' matches the coordinates of this file.
775 /// Check the full URL, including port and FQDN.
776 
777 Bool_t TNetFile::Matches(const char *url)
778 {
779  // Run standard check on fUrl, first
780  Bool_t rc = TFile::Matches(url);
781  if (rc)
782  // Ok, standard check enough
783  return kTRUE;
784 
785  // Check also endpoint URL
786  TUrl u(url);
787  if (!strcmp(u.GetFile(),fEndpointUrl.GetFile())) {
788  // Candidate info
789  TString fqdn = u.GetHostFQDN();
790 
791  // Check ports
792  if (u.GetPort() == fEndpointUrl.GetPort()) {
793  TString fqdnref = fEndpointUrl.GetHostFQDN();
794  if (fqdn == fqdnref)
795  // Ok, coordinates match
796  return kTRUE;
797  }
798  }
799 
800  // Default is not matching
801  return kFALSE;
802 }
803 
804 //
805 // TNetSystem: the directory handler for net files
806 //
807 
808 ////////////////////////////////////////////////////////////////////////////////
809 /// Create helper class that allows directory access via rootd.
810 /// Use ftpowner = TRUE (default) if this instance is responsible
811 /// for cleaning of the underlying TFTP connection; this allows
812 /// to have control on the order of the final cleaning.
813 
815  : TSystem("-root", "Net file Helper System")
816 {
817  // name must start with '-' to bypass the TSystem singleton check
818  SetName("root");
819 
820  fDir = kFALSE;
821  fDirp = 0;
822  fFTP = 0;
823  fFTPOwner = ftpowner;
824  fUser = "";
825  fHost = "";
826  fPort = -1;
827  fIsLocal = kFALSE;
828 }
829 
830 ////////////////////////////////////////////////////////////////////////////////
831 /// Create helper class that allows directory access via rootd.
832 /// Use ftpowner = TRUE (default) if this instance is responsible
833 /// for cleaning of the underlying TFTP connection; this allows
834 /// to have control on the order of the final cleaning.
835 
836 TNetSystem::TNetSystem(const char *url, Bool_t ftpowner)
837  : TSystem("-root", "Net file Helper System")
838 {
839  // name must start with '-' to bypass the TSystem singleton check
840  SetName("root");
841 
842  fFTPOwner = ftpowner;
843  fIsLocal = kFALSE;
844  Create(url);
845 }
846 
847 ////////////////////////////////////////////////////////////////////////////////
848 /// Parse and save coordinates of the remote entity (user, host, port, ...)
849 
850 void TNetSystem::InitRemoteEntity(const char *url)
851 {
852  TUrl turl(url);
853 
854  // Remote username: local as default
855  fUser = turl.GetUser();
856  if (!fUser.Length()) {
858  if (u)
859  fUser = u->fUser;
860  delete u;
861  }
862 
863  // Check and save the host FQDN ...
864  fHost = turl.GetHostFQDN();
865 
866  // Remote port: the default should be 1094 because we are here
867  // only if the protocol is "root://"
868  fPort = turl.GetPort();
869 }
870 
871 ////////////////////////////////////////////////////////////////////////////////
872 /// Create a TNetSystem object.
873 
874 void TNetSystem::Create(const char *url, TSocket *sock)
875 {
876  // If we got here protocol must be at least its short form "^root.*:" :
877  // make sure that it is in the full form to avoid problems in TFTP
878  TString surl(url);
879  if (!surl.Contains("://")) {
880  surl.Insert(surl.Index(":")+1,"//");
881  }
882  TUrl turl(surl);
883 
884  fDir = kFALSE;
885  fDirp = 0;
886  fFTP = 0;
887 
888  // Check locality, taking into account possible prefixes
889  fLocalPrefix = "";
890  fIsLocal = kFALSE;
891  // We may have been asked explicitly to go through the daemon
892  Bool_t forceRemote = gEnv->GetValue("Path.ForceRemote", 0);
893  TString opts = TUrl(url).GetOptions();
894  if (opts.Contains("remote=1"))
895  forceRemote = kTRUE;
896  else if (opts.Contains("remote=0"))
897  forceRemote = kFALSE;
898  if (!forceRemote) {
899  if ((fIsLocal = TSystem::IsPathLocal(url))) {
900  fLocalPrefix = gEnv->GetValue("Path.Localroot","");
901  // Nothing more to do
902  return;
903  }
904  }
905 
906  // Fill in user, host, port
907  InitRemoteEntity(surl);
908 
909  // Build a TFTP url
910  if (fHost.Length()) {
911  TString eurl = "";
912  // First the protocol
913  if (strlen(turl.GetProtocol())) {
914  eurl = turl.GetProtocol();
915  eurl += "://";
916  } else
917  eurl = "root://";
918  // Add user, if specified
919  if (strlen(turl.GetUser())) {
920  eurl += turl.GetUser();
921  eurl += "@";
922  }
923  // Add host
924  eurl += fHost;
925  // Add port
926  eurl += ":";
927  eurl += turl.GetPort();
928 
929  fFTP = new TFTP(eurl, 1, TFTP::kDfltWindowSize, sock);
930  if (fFTP && fFTP->IsOpen()) {
931  if (fFTP->GetSocket()->GetRemoteProtocol() < 12) {
932  Error("Create",
933  "remote daemon does not support 'system' functionality");
934  fFTP->Close();
935  delete fFTP;
936  } else {
939  // If responsible for the TFTP connection, remove it from the
940  // socket global list to avoid problems with double deletion
941  // at final cleanup
942  if (fFTPOwner)
943  gROOT->GetListOfSockets()->Remove(fFTP);
944  }
945  }
946  }
947 }
948 
949 ////////////////////////////////////////////////////////////////////////////////
950 /// Destructor
951 
953 {
954  // Close FTP connection
955  if (fFTPOwner) {
956  if (fFTP) {
957  if (fFTP->IsOpen()) {
958 
959  // Close remote directory if still open
960  if (fDir) {
962  fDir = kFALSE;
963  }
964  fFTP->Close();
965  }
966  delete fFTP;
967  }
968  }
969  fDirp = 0;
970  fFTP = 0;
971 }
972 
973 ////////////////////////////////////////////////////////////////////////////////
974 /// Make a directory via rootd.
975 
977 {
978  // If local, use the local TSystem
979  if (fIsLocal) {
980  TString edir = TUrl(dir).GetFile();
981  if (!fLocalPrefix.IsNull())
982  edir.Insert(0, fLocalPrefix);
983  return gSystem->MakeDirectory(edir);
984  }
985 
986  if (fFTP && fFTP->IsOpen()) {
987  // Extract the directory name
988  TString edir = TUrl(dir).GetFile();
989  return fFTP->MakeDirectory(edir,kFALSE);
990  }
991  return -1;
992 }
993 
994 ////////////////////////////////////////////////////////////////////////////////
995 /// Open a directory via rfiod. Returns an opaque pointer to a dir
996 /// structure. Returns 0 in case of error.
997 
998 void *TNetSystem::OpenDirectory(const char *dir)
999 {
1000  // If local, use the local TSystem
1001  if (fIsLocal) {
1002  TString edir = TUrl(dir).GetFile();
1003  if (!fLocalPrefix.IsNull())
1004  edir.Insert(0, fLocalPrefix);
1005  return gSystem->OpenDirectory(edir);
1006  }
1007 
1008  if (!fFTP || !fFTP->IsOpen())
1009  return (void *)0;
1010 
1011  if (fDir) {
1012  if (gDebug > 0)
1013  Info("OpenDirectory", "a directory is already open: close it first");
1015  fDir = kFALSE;
1016  }
1017 
1018  // Extract the directory name
1019  TString edir = TUrl(dir).GetFile();
1020 
1021  if (fFTP->OpenDirectory(edir,kFALSE)) {
1022  fDir = kTRUE;
1023  fDirp = (void *)&fDir;
1024  return fDirp;
1025  } else
1026  return (void *)0;
1027 }
1028 
1029 ////////////////////////////////////////////////////////////////////////////////
1030 /// Free directory via rootd.
1031 
1033 {
1034  // If local, use the local TSystem
1035  if (fIsLocal) {
1036  gSystem->FreeDirectory(dirp);
1037  return;
1038  }
1039 
1040  if (dirp != fDirp) {
1041  Error("FreeDirectory", "invalid directory pointer (should never happen)");
1042  return;
1043  }
1044 
1045  if (fFTP && fFTP->IsOpen()) {
1046  if (fDir) {
1048  fDir = kFALSE;
1049  fDirp = 0;
1050  }
1051  }
1052 }
1053 
1054 ////////////////////////////////////////////////////////////////////////////////
1055 /// Get directory entry via rootd. Returns 0 in case no more entries.
1056 
1057 const char *TNetSystem::GetDirEntry(void *dirp)
1058 {
1059  // If local, use the local TSystem
1060  if (fIsLocal) {
1061  return gSystem->GetDirEntry(dirp);
1062  }
1063 
1064  if (dirp != fDirp) {
1065  Error("GetDirEntry", "invalid directory pointer (should never happen)");
1066  return 0;
1067  }
1068 
1069  if (fFTP && fFTP->IsOpen() && fDir) {
1070  return fFTP->GetDirEntry(kFALSE);
1071  }
1072  return 0;
1073 }
1074 
1075 ////////////////////////////////////////////////////////////////////////////////
1076 /// Get info about a file. Info is returned in the form of a FileStat_t
1077 /// structure (see TSystem.h).
1078 /// The function returns 0 in case of success and 1 if the file could
1079 /// not be stat'ed.
1080 
1082 {
1083  // If local, use the local TSystem
1084  if (fIsLocal) {
1085  TString epath = TUrl(path).GetFile();
1086  if (!fLocalPrefix.IsNull())
1087  epath.Insert(0, fLocalPrefix);
1088  return gSystem->GetPathInfo(epath, buf);
1089  }
1090 
1091  if (fFTP && fFTP->IsOpen()) {
1092  // Extract the directory name
1093  TString epath = TUrl(path).GetFile();
1094  fFTP->GetPathInfo(epath, buf, kFALSE);
1095  return 0;
1096  }
1097  return 1;
1098 }
1099 
1100 ////////////////////////////////////////////////////////////////////////////////
1101 /// Returns FALSE if one can access a file using the specified access mode.
1102 /// Mode is the same as for the Unix access(2) function.
1103 /// Attention, bizarre convention of return value!!
1104 
1106 {
1107  // If local, use the local TSystem
1108  if (fIsLocal) {
1109  TString epath = TUrl(path).GetFile();
1110  if (!fLocalPrefix.IsNull())
1111  epath.Insert(0, fLocalPrefix);
1112  return gSystem->AccessPathName(epath, mode);
1113  }
1114 
1115  if (fFTP && fFTP->IsOpen()) {
1116  // Extract the directory name
1117  TString epath = TUrl(path).GetFile();
1118  return fFTP->AccessPathName(epath, mode, kFALSE);
1119  }
1120  return kTRUE;
1121 }
1122 
1123 ////////////////////////////////////////////////////////////////////////////////
1124 /// Check consistency of this helper with the one required
1125 /// by 'path' or 'dirptr'.
1126 
1127 Bool_t TNetSystem::ConsistentWith(const char *path, void *dirptr)
1128 {
1129  // Standard check: only the protocol part of 'path' is required to match
1130  Bool_t checkstd = TSystem::ConsistentWith(path, dirptr);
1131  if (!checkstd) return kFALSE;
1132 
1133  // Require match of 'user' and 'host'
1134  Bool_t checknet = path ? kFALSE : kTRUE;
1135  if (path && strlen(path)) {
1136 
1137  // Get user name
1138  TUrl url(path);
1139  TString user = url.GetUser();
1140  if (user.IsNull() && !fUser.IsNull()) {
1142  if (u)
1143  user = u->fUser;
1144  delete u;
1145  }
1146 
1147  // Get host name
1148  TString host = url.GetHostFQDN();
1149 
1150  // Get port
1151  Int_t port = url.GetPort();
1152  if (gDebug > 1)
1153  Info("ConsistentWith", "fUser:'%s' (%s), fHost:'%s' (%s), fPort:%d (%d)",
1154  fUser.Data(), user.Data(), fHost.Data(), host.Data(),
1155  fPort, port);
1156 
1157  if (user == fUser && host == fHost && port == fPort)
1158  checknet = kTRUE;
1159  }
1160 
1161  return (checkstd && checknet);
1162 }
1163 
1164 ////////////////////////////////////////////////////////////////////////////////
1165 /// Remove a path
1166 
1167 Int_t TNetSystem::Unlink(const char *path)
1168 {
1169  // If local, use the local TSystem
1170  if (fIsLocal) {
1171  TString epath = TUrl(path).GetFile();
1172  if (!fLocalPrefix.IsNull())
1173  epath.Insert(0, fLocalPrefix);
1174  return gSystem->Unlink(epath);
1175  }
1176 
1177  // Not implemented for rootd
1178  Warning("Unlink", "functionality not implemented - ignored (path: %s)", path);
1179  return -1;
1180 }
const char * GetHost() const
Definition: TUrl.h:76
TString fTitle
Definition: TNamed.h:37
ClassImp(TNetFile) ClassImp(TNetSystem) TNetFile
Create a TNetFile object.
Definition: TNetFile.cxx:79
const char * GetDirEntry(void *dirp=0)
Get directory entry via rootd. Returns 0 in case no more entries.
Definition: TNetFile.cxx:1057
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
Definition: TSystem.cxx:1213
Int_t GetPathInfo(const char *path, FileStat_t &buf, Bool_t print=kFALSE)
Get info about a file.
Definition: TFTP.cxx:1029
Bool_t AccessPathName(const char *path, EAccessMode mode)
Returns FALSE if one can access a file using the specified access mode.
Definition: TNetFile.cxx:1105
double read(const std::string &file_name)
reading
TNetFile()
Definition: TNetFile.h:74
virtual void ConnectServer(Int_t *stat, EMessageTypes *kind, Int_t netopt, Int_t tcpwindowsize, Bool_t forceOpen, Bool_t forceRead)
Connect to remote rootd server.
Definition: TNetFile.cxx:581
Int_t SysClose(Int_t fd)
Close currently open file.
Definition: TNetFile.cxx:155
virtual Bool_t IsPathLocal(const char *path)
Returns TRUE if the url in 'path' points to the local file system.
Definition: TSystem.cxx:1222
Bool_t fDir
Definition: TNetFile.h:98
long long Long64_t
Definition: RtypesCore.h:69
Long64_t fBytesWrite
Number of bytes written to this file.
Definition: TFile.h:62
Int_t GetRemoteProtocol() const
Definition: TSocket.h:156
R__EXTERN const char * gRootdErrStr[]
Definition: NetErrors.h:74
static std::atomic< Long64_t > fgBytesRead
Number of bytes read by all TFile objects.
Definition: TFile.h:111
Ssiz_t Length() const
Definition: TString.h:390
virtual Int_t ReOpen(Option_t *mode)
Reopen a file with a different access mode.
Definition: TFile.cxx:1971
const char Option_t
Definition: RtypesCore.h:62
Bool_t fFTPOwner
Definition: TNetFile.h:102
TFTP * fFTP
Definition: TNetFile.h:100
tuple offset
Definition: tree.py:93
virtual Int_t Send(const TMessage &mess)
Send a TMessage object.
Definition: TSocket.cxx:520
virtual void SetOffset(Long64_t offset, ERelativeTo pos=kBeg)
Set position from where to start reading.
Definition: TFile.cxx:2064
This class represents a WWW compatible URL.
Definition: TUrl.h:41
int GetPathInfo(const char *path, Long_t *id, Long_t *size, Long_t *flags, Long_t *modtime)
Get info about a file: id, size, flags, modification time.
Definition: TSystem.cxx:1311
Int_t MakeDirectory(const char *dir, Bool_t print=kFALSE) const
Make a remote directory.
Definition: TFTP.cxx:667
virtual Int_t Recv(TMessage *&mess)
Receive a TMessage object.
Definition: TSocket.cxx:818
virtual void SetName(const char *name)
Change (i.e.
Definition: TNamed.cxx:128
const char * GetProtocol() const
Definition: TUrl.h:73
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:892
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:45
static void SetFileReadCalls(Int_t readcalls=0)
Definition: TFile.cxx:4359
Bool_t Matches(const char *url)
Return kTRUE if 'url' matches the coordinates of this file.
Definition: TNetFile.cxx:777
const char * GetUser() const
Definition: TSecContext.h:88
virtual int MakeDirectory(const char *name)
Make a directory.
Definition: TSystem.cxx:821
void ToUpper()
Change string to upper case.
Definition: TString.cxx:1088
const char * GetHost() const
Definition: TSecContext.h:81
#define gROOT
Definition: TROOT.h:344
void Flush()
Flush file to disk.
Definition: TNetFile.cxx:236
TNetSystem(const TNetSystem &)
Basic string class.
Definition: TString.h:137
TAlienJobStatus * status
Definition: TAlienJob.cxx:51
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
Int_t WriteBufferViaCache(const char *buf, Int_t len)
Write buffer via cache.
Definition: TFile.cxx:2331
Bool_t OpenDirectory(const char *name, Bool_t print=kFALSE)
Open a directory via rootd.
Definition: TFTP.cxx:914
Definition: TFTP.h:42
void Create(const char *url, TSocket *sock=0)
Create a TNetSystem object.
Definition: TNetFile.cxx:874
ERelativeTo
Definition: TFile.h:160
R__EXTERN TApplication * gApplication
Definition: TApplication.h:171
TString fHost
Definition: TNetFile.h:101
virtual void IgnoreInterrupt(Bool_t ignore=kTRUE)
If ignore is true ignore the interrupt signal, else restore previous behaviour.
Definition: TSystem.cxx:606
Int_t fReadCalls
Number of read calls ( not counting the cache calls )
Definition: TFile.h:76
const char * GetOptions() const
Definition: TUrl.h:80
int Unlink(const char *path)
Remove a path.
Definition: TNetFile.cxx:1167
Int_t fPort
Definition: TNetFile.h:104
TString & Insert(Ssiz_t pos, const char *s)
Definition: TString.h:592
Int_t GetPathInfo(const char *path, FileStat_t &buf)
Get info about a file.
Definition: TNetFile.cxx:1081
TSignalHandler * GetSignalHandler() const
Definition: TApplication.h:112
Bool_t R_ISREG(Int_t mode)
Definition: TSystem.h:129
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:732
static Int_t GetErrno()
Static function returning system error number.
Definition: TSystem.cxx:264
static void SetFileBytesWritten(Long64_t bytes=0)
Definition: TFile.cxx:4356
const char * Data() const
Definition: TString.h:349
virtual Int_t SendRaw(const void *buffer, Int_t length, ESendRecvOptions opt=kDefault)
Send a raw buffer of specified length.
Definition: TSocket.cxx:620
virtual const char * GetDirEntry(void *dirp)
Get a directory entry. Returns 0 if no more entries.
Definition: TSystem.cxx:847
#define SafeDelete(p)
Definition: RConfig.h:436
virtual int Unlink(const char *name)
Unlink, i.e. remove, a file.
Definition: TSystem.cxx:1294
TUrl fUrl
!URL of file
Definition: TFile.h:97
Int_t fD
File descriptor.
Definition: TFile.h:69
static Long64_t GetFileBytesRead()
Static function returning the total number of bytes read from all files.
Definition: TFile.cxx:4319
Bool_t fIsLocal
Definition: TNetFile.h:112
static Long64_t GetFileBytesWritten()
Static function returning the total number of bytes written to all files.
Definition: TFile.cxx:4328
Int_t ReOpen(Option_t *mode)
Reopen a file with a different access mode, like from READ to UPDATE or from NEW, CREATE...
Definition: TNetFile.cxx:296
static TSocket * CreateAuthSocket(const char *user, const char *host, Int_t port, Int_t size=0, Int_t tcpwindowsize=-1, TSocket *s=0, Int_t *err=0)
Creates a socket or a parallel socket and authenticates to the remote server specified in 'url' on re...
Definition: TSocket.cxx:1457
virtual Bool_t IsAuthenticated() const
Definition: TSocket.h:161
virtual UserGroup_t * GetUserInfo(Int_t uid)
Returns all user info in the UserGroup_t structure.
Definition: TSystem.cxx:1511
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:918
virtual Bool_t ConsistentWith(const char *path, void *dirptr=0)
Check consistency of this helper with the one required by 'path' or 'dirptr'.
Definition: TSystem.cxx:798
void PrintError(const char *where, Int_t err)
Print error string depending on error code.
Definition: TNetFile.cxx:281
Bool_t IsValid() const
Definition: TUrl.h:88
static const char * what
Definition: stlLoader.cc:6
Int_t GetPort() const
Definition: TUrl.h:87
TString fUser
Definition: TNetFile.h:48
Int_t fProtocol
Definition: TNetFile.h:50
TString fUser
Definition: TSystem.h:152
Int_t fNetopt
Definition: TNetFile.h:52
Int_t SysStat(Int_t fd, Long_t *id, Long64_t *size, Long_t *flags, Long_t *modtime)
Return file stat information.
Definition: TNetFile.cxx:167
R__EXTERN TSystem * gSystem
Definition: TSystem.h:545
TString fLocalPrefix
Definition: TNetFile.h:113
virtual Int_t GetValue(const char *name, Int_t dflt)
Returns the integer value for a resource.
Definition: TEnv.cxx:494
const char * GetHostFQDN() const
Return fully qualified domain name of url host.
Definition: TUrl.cxx:467
static void update(gsl_integration_workspace *workspace, double a1, double b1, double area1, double error1, double a2, double b2, double area2, double error2)
TSocket * GetSocket() const
Definition: TFTP.h:116
unsigned int UInt_t
Definition: RtypesCore.h:42
char * Form(const char *fmt,...)
static std::atomic< Long64_t > fgBytesWrite
Number of bytes written by all TFile objects.
Definition: TFile.h:110
static std::atomic< Int_t > fgReadCalls
Number of bytes read from all TFile objects.
Definition: TFile.h:113
void * OpenDirectory(const char *name)
Open a directory via rfiod.
Definition: TNetFile.cxx:998
Int_t MakeDirectory(const char *name)
Make a directory via rootd.
Definition: TNetFile.cxx:976
EMessageTypes
Definition: MessageTypes.h:27
const char * GetDirEntry(Bool_t print=kFALSE)
Get directory entry via rootd.
Definition: TFTP.cxx:988
Int_t Recv(Int_t &status, EMessageTypes &kind)
Return status from rootd server and message kind.
Definition: TNetFile.cxx:557
static Int_t GetFileReadCalls()
Static function returning the total number of read calls from all files.
Definition: TFile.cxx:4336
Bool_t IsNull() const
Definition: TString.h:387
void HandleDelayedSignal()
TUrl fEndpointUrl
Definition: TNetFile.h:47
virtual void Init(Bool_t create)
Initialize a TFile object.
Definition: TFile.cxx:581
void Seek(Long64_t offset, ERelativeTo pos=kBeg)
Set position from where to start reading.
Definition: TNetFile.cxx:573
Bool_t WriteBuffer(const char *buf, Int_t len)
Write specified byte range to remote file via rootd daemon.
Definition: TNetFile.cxx:499
virtual void FreeDirectory(void *dirp)
Free a directory.
Definition: TSystem.cxx:839
Int_t ReadBufferViaCache(char *buf, Int_t len)
Read buffer via cache.
Definition: TFile.cxx:1715
Bool_t fWritable
True if directory is writable.
#define Printf
Definition: TGeoToOCC.h:18
TString ToLower(const TString &s)
Return a lower-case version of str.
Definition: TString.cxx:1380
#define gPerfStats
TSocket * fSocket
Definition: TNetFile.h:49
const char * GetUrl(Bool_t withDeflt=kFALSE) const
Return full URL.
Definition: TUrl.cxx:385
Bool_t ReadBuffers(char *buf, Long64_t *pos, Int_t *len, Int_t nbuf)
Read a list of buffers given in pos[] and len[] and return it in a single buffer. ...
Definition: TNetFile.cxx:395
TString fUser
Definition: TNetFile.h:103
long Long_t
Definition: RtypesCore.h:50
Int_t SysOpen(const char *pathname, Int_t flags, UInt_t mode)
Open a remote file. Requires fOption to be set correctly.
Definition: TNetFile.cxx:120
virtual void Create(const char *url, Option_t *option, Int_t netopt)
Create a NetFile object.
Definition: TNetFile.cxx:671
const char * GetUrl() const
Definition: TSocket.h:160
void Close(Option_t *option="")
Close remote file.
Definition: TNetFile.cxx:219
double Double_t
Definition: RtypesCore.h:55
Bool_t IsOpen() const
Retruns kTRUE if file is open, kFALSE otherwise.
Definition: TNetFile.cxx:258
R__EXTERN TEnv * gEnv
Definition: TEnv.h:174
void dir(char *path=0)
Definition: rootalias.C:30
The TTimeStamp encapsulates seconds and ns since EPOCH.
Definition: TTimeStamp.h:76
TString fOption
File options.
Definition: TFile.h:78
virtual ~TNetFile()
TNetFile dtor. Send close message and close socket.
Definition: TNetFile.cxx:112
Int_t Close()
Close ftp connection.
Definition: TFTP.cxx:884
EAccessMode
Definition: TSystem.h:54
void * fDirp
Definition: TNetFile.h:99
Bool_t ConsistentWith(const char *path, void *dirptr)
Check consistency of this helper with the one required by 'path' or 'dirptr'.
Definition: TNetFile.cxx:1127
Bool_t FlushWriteCache()
Flush the write cache if active.
Definition: TFile.cxx:1097
TSecContext * GetSecContext() const
Definition: TSocket.h:157
Int_t fErrorCode
Definition: TNetFile.h:51
Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists, Bool_t print=kFALSE)
Returns kFALSE if one can access a file using the specified access mode.
Definition: TFTP.cxx:1111
Bool_t R_ISDIR(Int_t mode)
Definition: TSystem.h:126
Bool_t ReadBuffer(char *buf, Int_t len)
Read specified byte range from remote file via rootd daemon.
Definition: TNetFile.cxx:311
virtual Bool_t ReadBuffers(char *buf, Long64_t *pos, Int_t *len, Int_t nbuf)
Read the nbuf blocks described in arrays pos and len.
Definition: TFile.cxx:1647
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:567
void MakeZombie()
Definition: TObject.h:68
virtual ~TNetSystem()
Destructor.
Definition: TNetFile.cxx:952
void Print(Option_t *option) const
Print some info about the net file.
Definition: TNetFile.cxx:266
virtual void * OpenDirectory(const char *name)
Open a directory. Returns 0 if directory does not exist.
Definition: TSystem.cxx:830
R__EXTERN Int_t gDebug
Definition: Rtypes.h:128
void FreeDirectory(Bool_t print=kFALSE)
Free a remotely open directory via rootd.
Definition: TFTP.cxx:956
Long64_t fArchiveOffset
!Offset at which file starts in archive
Definition: TFile.h:88
static void ResetErrno()
Static function resetting system error number.
Definition: TSystem.cxx:280
#define gDirectory
Definition: TDirectory.h:221
double result[121]
Bool_t IsOpen() const
Definition: TFTP.h:93
void Init(Bool_t create)
Initialize a TNetFile object.
Definition: TNetFile.cxx:247
Long64_t fOffset
!Seek offset cache
Definition: TFile.h:83
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition: TString.h:582
static void SetFileBytesRead(Long64_t bytes=0)
Definition: TFile.cxx:4353
Abstract base class defining a generic interface to the underlying Operating System.
Definition: TSystem.h:258
virtual Int_t RecvRaw(void *buffer, Int_t length, ESendRecvOptions opt=kDefault)
Receive a raw buffer of specified length bytes.
Definition: TSocket.cxx:901
const Bool_t kTRUE
Definition: Rtypes.h:91
const Int_t n
Definition: legend1.C:16
const char * GetUser() const
Definition: TUrl.h:74
void InitRemoteEntity(const char *url)
Parse and save coordinates of the remote entity (user, host, port, ...)
Definition: TNetFile.cxx:850
void FreeDirectory(void *dirp=0)
Free directory via rootd.
Definition: TNetFile.cxx:1032
Long64_t fBytesRead
Number of bytes read from this file.
Definition: TFile.h:63
const char * GetFile() const
Definition: TUrl.h:78
virtual void Close(Option_t *option="")
Close a file.
Definition: TFile.cxx:898
virtual Bool_t Matches(const char *name)
Return kTRUE if 'url' matches the coordinates of this file.
Definition: TFile.cxx:4511
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:904