xrootd
XrdXrootdFile.hh
Go to the documentation of this file.
1 #ifndef _XROOTD_FILE_H_
2 #define _XROOTD_FILE_H_
3 /******************************************************************************/
4 /* */
5 /* X r d X r o o t d F i l e . h h */
6 /* */
7 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* All Rights Reserved. See XrdInfo.cc for complete License Terms */
9 /* Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC03-76-SFO0515 with the Department of Energy */
11 /******************************************************************************/
12 
13 #include <string.h>
14 
15 #include "XProtocol/XPtypes.hh"
16 
17 /******************************************************************************/
18 /* x r d _ F i l e */
19 /******************************************************************************/
20 
21 class XrdSfsFile;
22 class XrdXrootdFileLock;
23 class XrdXrootdMonitor;
24 
26 {
27 public:
28 
29 XrdSfsFile *XrdSfsp; // -> Actual file object
30 char *mmAddr; // Memory mapped location, if any
31 long long fSize; // File size at time of object creation
32 int fdNum; // File descriptor number if regular file
33 kXR_unt32 FileID; // Unique file id used for monitoring
34 char FileKey[34]; // -> Unique hash name for the file
35 char Reserved[2];
36 char FileMode; // 'r' or 'w'
37 char AsyncMode; // 1 -> if file in async r/w mode
38 char isMMapped; // 1 -> file is memory mapped
39 char sfEnabled; // 1 -> file is sendfile enabled
40 char *ID; // File user
41 long long readCnt;
42 long long writeCnt;
43 
44 static void Init(XrdXrootdFileLock *lp, int sfok) {Locker = lp; sfOK = sfok;}
45 
46  XrdXrootdFile(char *id, XrdSfsFile *fp, char mode='r',
47  char async='\0', int sfOK=0, struct stat *sP=0);
49 
50 private:
51 int bin2hex(char *outbuff, char *inbuff, int inlen);
53 static int sfOK;
54 static const char *TraceID;
55 };
56 
57 /******************************************************************************/
58 /* x r o o t d _ F i l e T a b l e */
59 /******************************************************************************/
60 
61 // The before define the structure of the file table. We will have FTABSIZE
62 // internal table entries. We will then provide an external linear table
63 // that increases by FTABSIZE entries. There is one file table per link and
64 // it is owned by the base protocol object.
65 //
66 #define XRD_FTABSIZE 16
67 
68 // WARNING! Manipulation (i.e., Add/Del/delete) of this object must be
69 // externally serialized at the link level. Only one thread
70 // may be active w.r.t this object during manipulation!
71 //
73 {
74 public:
75 
76  int Add(XrdXrootdFile *fp);
77 
78  void Del(int fnum);
79 
80 inline XrdXrootdFile *Get(int fnum)
81  {if (fnum >= 0)
82  {if (fnum < XRD_FTABSIZE) return FTab[fnum];
83  if (XTab && (fnum-XRD_FTABSIZE)<XTnum)
84  return XTab[fnum-XRD_FTABSIZE];
85  }
86  return (XrdXrootdFile *)0;
87  }
88 
89  void Recycle(XrdXrootdMonitor *monP=0, int doDel=1);
90 
91  XrdXrootdFileTable() {memset((void *)FTab, 0, sizeof(FTab));
92  FTfree = 0; XTab = 0; XTnum = XTfree = 0;
93  }
95 
96 private:
97 
98 static const char *TraceID;
99 
101 int FTfree;
102 
104 int XTnum;
105 int XTfree;
106 };
107 #endif