library: libCore #include "TNetFile.h"

# TNetFile

class description - source file - inheritance tree (.pdf)

## class TNetFile : public TFile

| Inheritance Chart:

`TObject`

<-

`TNamed`

<-

`TDirectory`

<-

`TFile`

<-

`TNetFile`

<-

`TCastorFile` |

`TXNetFile` |

        protected:

                        TNetFile(const char* url, const char* ftitle, Int_t comp, Bool_t)
           virtual void ConnectServer(Int_t* stat, EMessageTypes* kind, Int_t netopt, Int_t tcpwindowsize, Bool_t forceOpen, Bool_t forceRead)
           virtual void Create(const char* url, Option_t* option, Int_t netopt)
           virtual void Create(TSocket* s, Option_t* option, Int_t netopt)
                   void Init(Bool_t create)
           virtual void Print(Option_t* option) const
                   void PrintError(const char* where, Int_t err)
                  Int_t Recv(Int_t& status, EMessageTypes& kind)
          virtual Int_t SysClose(Int_t fd)
          virtual Int_t SysOpen(const char* pathname, Int_t flags, UInt_t mode)
          virtual Int_t SysStat(Int_t fd, Long_t* id, Long64_t* size, Long_t* flags, Long_t* modtime)

        public:

                          TNetFile(const char* url, Option_t* option = "", const char* ftitle = "", Int_t compress = 1, Int_t netopt = 0)
                          TNetFile()
                  virtual ~TNetFile()
           static TClass* Class()
             virtual void Close(Option_t* option = "")
             virtual void Flush()
                    Int_t GetErrorCode() const
          virtual TClass* IsA() const
           virtual Bool_t IsOpen() const
           virtual Bool_t ReadBuffer(char* buf, Int_t len)
            virtual Int_t ReOpen(Option_t* mode)
             virtual void Seek(Long64_t offset, TFile::ERelativeTo pos = kBeg)
             virtual void ShowMembers(TMemberInspector& insp, char* parent)
             virtual void Streamer(TBuffer& b)
                     void StreamerNVirtual(TBuffer& b)
           virtual Bool_t WriteBuffer(const char* buf, Int_t len)

### Data Members

        protected:

              TUrl fUrl        URL of file
           TString fUser       remote user name
          TSocket* fSocket     connection to rootd server
             Int_t fProtocol   rootd protocol level
             Int_t fErrorCode  error code returned by rootd (matching gRootdErrStr)

## Class Description

     TNetFile

     A TNetFile is like a normal TFile except that it reads and writes
     its data via a rootd server (for more on the rootd daemon see the
     source files root/rootd/src/*.cxx). TNetFile file names are in
     standard URL format with protocol "root" or "roots". The following
     are valid TNetFile URL's:

        roots://hpsalo/files/aap.root
        root://hpbrun.cern.ch/root/hsimple.root
        root://pcna49a:5151/~na49/data/run821.root
        root://pcna49d.cern.ch:5050//v1/data/run810.root

     The only difference with the well known httpd URL's is that the root
     of the remote file tree is the user's home directory. Therefore an
     absolute pathname requires a // after the host or port specifier
     (see last example). Further the expansion of the standard shell
     characters, like ~, $, .., are handled as expected.
     TNetFile (actually TUrl) uses 1094 as default port for rootd.

     Connecting to a rootd requires the remote user id and password.
     TNetFile allows three ways for you to provide your login:
       1) Setting it globally via the static functions:
             TAuthenticate::SetGlobalUser() and
             TAuthenticate::SetGlobalPasswd()
       2) Getting it from the ~/.netrc file (same file as used by ftp)
       3) Command line prompt
     The different methods will be tried in the order given above.
     On machines with AFS rootd will authenticate using AFS (if it was
     compiled with AFS support).

     If the protocol is specified as "roots" a secure authetication
     method will be used. The secure method uses the SRP, Secure Remote
     Passwords, package. SRP uses a so called "asymmetric key exchange
     protocol" in which no passwords are ever send over the wire. This
     protocol is safe against all known security attacks. For more see:

NetFile

     If the protocol is specified as "rootk" kerberos5 will be used for
     authentication.

     The rootd daemon lives in the directory $ROOTSYS/bin. It can be
     started either via inetd or by hand from the command line (no need
     to be super user). For more info about rootd see the web page:

NetFile

TNetFile(const char *url, Option_t *option, const char *ftitle, Int_t compress, Int_t netopt) : TFile(url, "NET", ftitle, compress), fUrl(url)

     Create a TNetFile object. This is actually done inside Create(), so
     for a description of the options and other arguments see Create().
     Normally a TNetFile is created via TFile::Open().

TNetFile(const char *url, const char *ftitle, Int_t compress, Bool_t) : TFile(url, "NET", ftitle, compress), fUrl(url)

     Create a TNetFile object. To be used by derived classes, that need
     to initialize the TFile base class but not open a connection at this
     moment.

~TNetFile()

     TNetFile dtor. Send close message and close socket.

Int_t SysOpen(const char * /*file*/, Int_t /*flags*/, UInt_t /*mode*/)

     Open a remote file. Requires fOption to be set correctly.

Int_t SysClose(Int_t /*fd*/)

     Close currently open file.

Int_t SysStat(Int_t, Long_t *id, Long64_t *size, Long_t *flags, Long_t *modtime)

     Return file stat information. The interface and return value is
     identical to TSystem::GetPathInfo().

void Close(Option_t *opt)

     Close remote file.

void Flush()

     Flush file to disk.

void Init(Bool_t create)

     Initialize a TNetFile object.

Bool_t IsOpen() const

     Retruns kTRUE if file is open, kFALSE otherwise.

void Print(Option_t *) const

     Print some info about the net file.

void PrintError(const char *where, Int_t err)

     Print error string depending on error code.

Int_t ReOpen(Option_t *mode)

     Reopen a file with a different access mode, like from READ to
     UPDATE or from NEW, CREATE, RECREATE, UPDATE to READ. Thus the
     mode argument can be either "READ" or "UPDATE". The method returns
     0 in case the mode was successfully modified, 1 in case the mode
     did not change (was already as requested or wrong input arguments)
     and -1 in case of failure, in which case the file cannot be used
     anymore.

Bool_t ReadBuffer(char *buf, Int_t len)

     Read specified byte range from remote file via rootd daemon.
     Returns kTRUE in case of error.

Bool_t WriteBuffer(const char *buf, Int_t len)

     Write specified byte range to remote file via rootd daemon.
     Returns kTRUE in case of error.

Int_t Recv(Int_t &status, EMessageTypes &kind)

     Return status from rootd server and message kind. Returns -1 in
     case of error otherwise 8 (sizeof 2 words, status and kind).

void Seek(Long64_t offset, ERelativeTo pos)

     Set position from where to start reading.

void ConnectServer(Int_t *stat, EMessageTypes *kind, Int_t netopt, Int_t tcpwindowsize, Bool_t forceOpen, Bool_t forceRead)

     Connect to remote rootd server.

void Create(const char *url, Option_t *option, Int_t netopt)

     Create a NetFile object. A net file is the same as a TFile
     except that it is being accessed via a rootd server. The url
     argument must be of the form: root[s|k]://host.dom.ain/file.root.
     When protocol is "roots" try using SRP authentication.
     When protocol is "rootk" try using kerberos5 authentication.
     If the file specified in the URL does not exist, is not accessable
     or can not be created the kZombie bit will be set in the TNetFile
     object. Use IsZombie() to see if the file is accessable.
     If the remote daemon thinks the file is still connected, while you are
     sure this is not the case you can force open the file by preceding the
     option argument with an "-", e.g.: "-recreate". Do this only
     in cases when you are very sure nobody else is using the file.
     To bypass the writelock on a file, to allow the reading of a file
     that is being written by another process, explicitely specify the
     "+read" option ("read" being the default option).
     The netopt argument can be used to specify the size of the tcp window in
     bytes (for more info see: http://www.psc.edu/networking/perf_tune.html).
     The default and minimum tcp window size is 65535 bytes.
     If netopt < -1 then |netopt| is the number of parallel sockets that will
     be used to connect to rootd. This option should be used on fat pipes
     (i.e. high bandwidth, high latency links). The ideal number of parallel
     sockets depends on the bandwidth*delay product. Generally 5-7 is a good
     number.
     For a description of the option and other arguments see the TFile ctor.
     The preferred interface to this constructor is via TFile::Open().

void Create(TSocket *s, Option_t *option, Int_t netopt)

     Create a NetFile object using an existing connection (socket s).
     Provided for use in TXNetFile.
     See:
        TNetFile::Create(const char *url, Option_t *option, Int_t netopt)
     for details about the arguments.

### Inline Functions

               TNetFile TNetFile()
                  Int_t GetErrorCode() const
                TClass* Class()
                TClass* IsA() const
                   void ShowMembers(TMemberInspector& insp, char* parent)
                   void Streamer(TBuffer& b)
                   void StreamerNVirtual(TBuffer& b)

Author: Fons Rademakers 14/08/97
Last update: root/net:$Name: $:$Id: TNetFile.cxx,v 1.61 2005/05/31 13:29:12 rdm Exp $
Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *