Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TXNetFile.h
Go to the documentation of this file.
1 // @(#)root/netx:$Id$
2 /*************************************************************************
3  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. *
4  * All rights reserved. *
5  * *
6  * For the licensing terms see $ROOTSYS/LICENSE. *
7  * For the list of contributors see $ROOTSYS/README/CREDITS. *
8  *************************************************************************/
9 
10 #ifndef ROOT_TXNetFile
11 #define ROOT_TXNetFile
12 
13 
14 //////////////////////////////////////////////////////////////////////////
15 // //
16 // TXNetFile //
17 // //
18 // Authors: Alvise Dorigo, Fabrizio Furano //
19 // INFN Padova, 2003 //
20 // Interfaced to the posix client: G. Ganis, CERN //
21 // //
22 // TXNetFile is an extension of TNetFile able to deal with new xrootd //
23 // server. Its new features are: //
24 // - Automatic server kind recognition (xrootd load balancer, xrootd //
25 // data server, old rootd) //
26 // - Backward compatibility with old rootd server (acts as an old //
27 // TNetFile) //
28 // - Fault tolerance for read/write operations (read/write timeouts //
29 // and retry) //
30 // - Internal connection timeout (tunable indipendently from the OS //
31 // one) handled by threads //
32 // - handling of redirections from server //
33 // - Single TCP physical channel for multiple TXNetFile's instances //
34 // inside the same application //
35 // So, each TXNetFile object client must send messages containing //
36 // its ID (streamid). The server, of course, will respond with //
37 // messages containing the client's ID, in order to make the client //
38 // able to recognize its message by matching its streamid with that //
39 // one contained in the server's response. //
40 // - Tunable log verbosity level (0 = nothing, 3 = dump read/write //
41 // buffers too!) //
42 // - Many parameters configurable via TEnv facility (see SetParm() //
43 // methods) //
44 // //
45 //////////////////////////////////////////////////////////////////////////
46 
47 #include "TNetFile.h"
48 #include "TString.h"
49 #include "TUrl.h"
50 
51 class TFileStager;
52 class TSocket;
53 class XrdClient;
54 
55 class TXNetFile : public TNetFile {
56 
57 friend class TXNetSystem;
58 
59 private:
60  // Static members
61  static Bool_t fgInitDone; // Avoid initializing more than once
62  static Bool_t fgRootdBC; // Control rootd backward compatibility
63  static TFileStager *fgFileStager; // Stager for IsStaged checks
64 
65  // Members
66  XrdClient *fClient; // Handle to the client object
67  Bool_t fIsRootd; // Nature of remote file server
68  void *fInitMtx; // Protects fInitDone, serializes the
69  // attempts to Init() for this object only
70 
71  // Methods
72  TXNetFile(const TXNetFile&); // Not implemented
73  TXNetFile& operator=(const TXNetFile&); // Not implemented
74  void CreateXClient(const char *url, Option_t *option, Int_t netopt,
75  Bool_t parallelopen);
76 
77  Int_t ParseOptions(const char *opts, Int_t &cachesz, Int_t &readaheadsz,
78  Int_t &rmpolicy, Int_t &mxredir, Int_t &rastrategy, Int_t &readtrimblksz);
79 
80  // Synchronizes the cache size in XrdClient
81  // XrdClient cannot have a cache size smaller than the one in TFile
82  void SynchronizeCacheSize();
83 
84  void Init(Bool_t create);
85  Bool_t Open(Option_t *option, Bool_t parallelopen);
86  Int_t SysStat(Int_t fd, Long_t *id, Long64_t *size, Long_t *flags,
87  Long_t *modtime);
88  Int_t SysOpen(const char *pathname, Int_t flags, UInt_t mode);
89  Int_t SysClose(Int_t fd);
90 
91  // Static methods
92  static void FormUrl(TUrl uut, TString &uu);
93  static Int_t GetRootdProtocol(TSocket *s);
94  static void SetEnv();
95 
96 public:
97  TXNetFile() : TNetFile(), fClient(0), fIsRootd(0), fInitMtx(0) {}
98  TXNetFile(const char *url, Option_t *option = "", const char *fTitle = "",
99  Int_t compress = 1, Int_t netopt = 0, Bool_t parallelopen = kFALSE,
100  const char *logicalurl = 0);
101 
102  virtual ~TXNetFile();
103 
104  virtual void Close(const Option_t *opt ="");
105  virtual void ResetCache();
106  virtual void Flush();
107  virtual Int_t GetBytesToPrefetch() const;
108  virtual Bool_t ReadBufferAsync(Long64_t offs, Int_t len);
109  virtual TFile::EAsyncOpenStatus GetAsyncOpenStatus();
110  virtual Bool_t IsOpen() const;
111 
112  virtual void Print(Option_t *option="") const;
113  virtual Bool_t ReadBuffer(char *buf, Int_t len);
114  virtual Bool_t ReadBuffer(char *buf, Long64_t pos, Int_t len);
115  virtual Bool_t ReadBuffers(char *buf, Long64_t *pos, Int_t *len, Int_t nbuf);
116  virtual Int_t ReOpen(const Option_t *mode);
117  virtual Bool_t WriteBuffer(const char *buffer, Int_t BufferLength);
118 
119  ClassDef(TXNetFile,0) // TFile implementation to deal with new xrootd server.
120 };
121 
122 #endif