Logo ROOT   6.14/05
Reference Guide
Go to the documentation of this file.
1 // @(#)root/net:$Id$
2 // Author: Fons Rademakers 14/08/97
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  *************************************************************************/
12 #ifndef ROOT_TNetFile
13 #define ROOT_TNetFile
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TNetFile //
19 // //
20 // A TNetFile is like a normal TFile except that it reads and writes //
21 // its data via a rootd server. //
22 // //
23 //////////////////////////////////////////////////////////////////////////
25 #include "TFile.h"
26 #include "TUrl.h"
27 #include "TFTP.h"
28 #include "TSystem.h"
29 #include "MessageTypes.h"
31 class TSocket;
34 class TNetFile : public TFile {
36 protected:
37  TUrl fEndpointUrl; //URL of realfile (after possible redirection)
38  TString fUser; //remote user name
39  TSocket *fSocket; //connection to rootd server
40  Int_t fProtocol; //rootd protocol level
41  Int_t fErrorCode; //error code returned by rootd (matching gRootdErrStr)
42  Int_t fNetopt; //initial network options (used for ReOpen())
44  TNetFile(const TNetFile&); // NetFile cannot be copied
45  TNetFile& operator=(const TNetFile&); // NetFile cannot be copied
47  TNetFile(const char *url, const char *ftitle, Int_t comp, Bool_t);
48  virtual void ConnectServer(Int_t *stat, EMessageTypes *kind, Int_t netopt,
49  Int_t tcpwindowsize, Bool_t forceOpen,
50  Bool_t forceRead);
51  virtual void Create(const char *url, Option_t *option, Int_t netopt);
52  virtual void Create(TSocket *s, Option_t *option, Int_t netopt);
53  void Init(Bool_t create);
54  void Print(Option_t *option) const;
55  void PrintError(const char *where, Int_t err);
56  Int_t Recv(Int_t &status, EMessageTypes &kind);
57  Int_t SysOpen(const char *pathname, Int_t flags, UInt_t mode);
58  Int_t SysClose(Int_t fd);
59  Int_t SysStat(Int_t fd, Long_t *id, Long64_t *size, Long_t *flags, Long_t *modtime);
61 public:
62  TNetFile(const char *url, Option_t *option = "", const char *ftitle = "",
63  Int_t compress = 1, Int_t netopt = 0);
64  TNetFile() : fEndpointUrl(), fUser(), fSocket(0), fProtocol(0), fErrorCode(0), fNetopt(0) { }
65  virtual ~TNetFile();
67  void Close(Option_t *option=""); // *MENU*
68  void Flush();
69  Int_t GetErrorCode() const { return fErrorCode; }
70  Bool_t IsOpen() const;
71  Bool_t Matches(const char *url);
72  Int_t ReOpen(Option_t *mode);
73  Bool_t ReadBuffer(char *buf, Int_t len);
74  Bool_t ReadBuffer(char *buf, Long64_t pos, Int_t len);
75  Bool_t ReadBuffers(char *buf, Long64_t *pos, Int_t *len, Int_t nbuf);
76  Bool_t WriteBuffer(const char *buf, Int_t len);
77  void Seek(Long64_t offset, ERelativeTo pos = kBeg);
79  const TUrl *GetEndpointUrl() const { return &fEndpointUrl; }
81  ClassDef(TNetFile,1) //A ROOT file that reads/writes via a rootd server
82 };
85 class TNetSystem : public TSystem {
87 private:
88  Bool_t fDir; // true if a directory is open remotely
89  void *fDirp; // directory handler
90  TFTP *fFTP; // Connection to rootd
91  TString fHost; // Remote host
92  Bool_t fFTPOwner; // True if owner of the FTP instance
93  TString fUser; // Remote user
94  Int_t fPort; // Remote port
96  TNetSystem(const TNetSystem&); // not implemented
97  TNetSystem& operator=(const TNetSystem&); // not implemented
99  void *GetDirPtr() const { return fDirp; }
101 protected:
102  Bool_t fIsLocal; // TRUE if the path points to this host
103  TString fLocalPrefix; // if fIsLocal, prefix to be prepend locally
105  void Create(const char *url, TSocket *sock = 0);
106  void InitRemoteEntity(const char *url);
108 public:
109  TNetSystem(Bool_t ftpowner = kTRUE);
110  TNetSystem(const char *url, Bool_t ftpowner = kTRUE);
111  virtual ~TNetSystem();
113  Bool_t ConsistentWith(const char *path, void *dirptr);
114  Int_t MakeDirectory(const char *name);
115  void *OpenDirectory(const char *name);
116  void FreeDirectory(void *dirp = 0);
117  const char *GetDirEntry(void *dirp = 0);
118  Int_t GetPathInfo(const char *path, FileStat_t &buf);
119  Bool_t AccessPathName(const char *path, EAccessMode mode);
120  int Unlink(const char *path);
122  ClassDef(TNetSystem,0) // Directory handler for NetSystem
123 };
125 #endif
Definition: TNetFile.h:64
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
Bool_t fDir
Definition: TNetFile.h:88
long long Long64_t
Definition: RtypesCore.h:69
const char Option_t
Definition: RtypesCore.h:62
Bool_t fFTPOwner
Definition: TNetFile.h:92
Definition: TNetFile.h:90
This class represents a WWW compatible URL.
Definition: TUrl.h:35
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:47
Bool_t Matches(const char *url)
Return kTRUE if 'url' matches the coordinates of this file.
Definition: TNetFile.cxx:777
TNetFile & operator=(const TNetFile &)
void Flush()
Flush file to disk.
Definition: TNetFile.cxx:236
Basic string class.
Definition: TString.h:131
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Definition: TFTP.h:34
Definition: TFile.h:183
TString fHost
Definition: TNetFile.h:91
void * GetDirPtr() const
Definition: TNetFile.h:99
Int_t fPort
Definition: TNetFile.h:94
#define ClassDef(name, id)
Definition: Rtypes.h:320
Bool_t fIsLocal
Definition: TNetFile.h:102
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
void PrintError(const char *where, Int_t err)
Print error string depending on error code.
Definition: TNetFile.cxx:281
TString fUser
Definition: TNetFile.h:38
Int_t fProtocol
Definition: TNetFile.h:40
Int_t fNetopt
Definition: TNetFile.h:42
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
TString fLocalPrefix
Definition: TNetFile.h:103
unsigned int UInt_t
Definition: RtypesCore.h:42
Definition: MessageTypes.h:27
Int_t Recv(Int_t &status, EMessageTypes &kind)
Return status from rootd server and message kind.
Definition: TNetFile.cxx:557
TUrl fEndpointUrl
Definition: TNetFile.h:37
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
TSocket * fSocket
Definition: TNetFile.h:39
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:93
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
void Close(Option_t *option="")
Close remote file.
Definition: TNetFile.cxx:219
static constexpr double s
virtual ~TNetFile()
TNetFile dtor. Send close message and close socket.
Definition: TNetFile.cxx:112
Definition: TSystem.h:44
void * fDirp
Definition: TNetFile.h:89
Int_t fErrorCode
Definition: TNetFile.h:41
Bool_t ReadBuffer(char *buf, Int_t len)
Read specified byte range from remote file via rootd daemon.
Definition: TNetFile.cxx:311
const TUrl * GetEndpointUrl() const
Definition: TNetFile.h:79
Bool_t IsOpen() const
Retruns kTRUE if file is open, kFALSE otherwise.
Definition: TNetFile.cxx:258
Int_t GetErrorCode() const
Definition: TNetFile.h:69
void Init(Bool_t create)
Initialize a TNetFile object.
Definition: TNetFile.cxx:247
Abstract base class defining a generic interface to the underlying Operating System.
Definition: TSystem.h:248
const Bool_t kTRUE
Definition: RtypesCore.h:87
char name[80]
Definition: TGX11.cxx:109
void Print(Option_t *option) const
Print some info about the net file.
Definition: TNetFile.cxx:266