xrootd
XrdPoll.hh
Go to the documentation of this file.
00001 #ifndef __XRD_POLL_H__
00002 #define __XRD_POLL_H__
00003 /******************************************************************************/
00004 /*                                                                            */
00005 /*                            X r d P o l l . h h                             */
00006 /*                                                                            */
00007 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University  */
00008 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00009 /*              DE-AC03-76-SFO0515 with the Department of Energy              */
00010 /******************************************************************************/
00011 
00012 #include <sys/poll.h>
00013 #include "XrdSys/XrdSysPthread.hh"
00014 
00015 #define XRD_NUMPOLLERS 3
00016 
00017 class XrdOucTrace;
00018 class XrdSysError;
00019 class XrdLink;
00020 class XrdScheduler;
00021 class XrdSysSemaphore;
00022   
00023 class XrdPoll
00024 {
00025 public:
00026 
00027 // Attach() is called when a new link needs to be assigned to a poller
00028 //
00029 static  int   Attach(XrdLink *lp);    // Implementation supplied
00030 
00031 // Detach() is called when a link is being discarded
00032 //
00033 static  void  Detach(XrdLink *lp);   //  Implementation supplied
00034 
00035 // Disable() is called when we need to mask interrupts from a link
00036 //
00037 virtual void  Disable(XrdLink *lp, const char *etxt=0) = 0;
00038 
00039 // Enable() is called when we want to receive interrupts from a link
00040 //
00041 virtual int   Enable(XrdLink *lp)  = 0;
00042 
00043 // Finish() is called to allow a link to gracefully terminate when scheduled
00044 //
00045 static  int   Finish(XrdLink *lp, const char *etxt=0); //Implementation supplied
00046 
00047 // Init()   is called to set pointers to external interfaces at config time.
00048 //
00049 static  void  Init(XrdSysError *eP, XrdOucTrace *tP, XrdScheduler *sP)
00050                   {XrdLog = eP; XrdTrace = tP; XrdSched = sP;}
00051 
00052 // Poll2Text() converts bits in an revents item to text
00053 //
00054 static  char *Poll2Text(short events); // Implementation supplied
00055 
00056 // Setup() is called at config time to perform poller configuration
00057 //
00058 static  int   Setup(int numfd);        // Implementation supplied
00059 
00060 // Start() is called via a thread for each poller that was created
00061 //
00062 virtual void  Start(XrdSysSemaphore *syncp, int &rc) = 0;
00063 
00064 // Stats() is called to provide statistics on polling
00065 //
00066 static  int   Stats(char *buff, int blen, int do_sync=0);
00067 
00068 // Identification of the thread handling this object
00069 //
00070            int         PID;       // Poller ID
00071            pthread_t   TID;       // Thread ID
00072 
00073 // The following table reference the pollers in effect
00074 //
00075 static     XrdPoll   *Pollers[XRD_NUMPOLLERS];
00076 
00077            XrdPoll();
00078 virtual   ~XrdPoll() {}
00079 
00080 protected:
00081 
00082 static     const char   *TraceID;                  // For tracing
00083 static     XrdOucTrace  *XrdTrace;
00084 static     XrdSysError  *XrdLog;
00085 static     XrdScheduler *XrdSched;
00086 
00087 // Gets the next request on the poll pipe. This is common to all implentations.
00088 //
00089            int         getRequest();             // Implementation supplied
00090 
00091 // Exclude() called to exclude a link from a poll set
00092 //
00093 virtual    void        Exclude(XrdLink *lp) = 0;
00094 
00095 // Include() called to include a link in a poll set
00096 //
00097 virtual    int         Include(XrdLink *lp) = 0;
00098 
00099 // newPoller() called to get a new poll object at initialization time
00100 //             Even though static, an implementation must be supplied.
00101 //
00102 static     XrdPoll   *newPoller(int pollid, int numfd)    /* = 0 */;
00103 
00104 // The following is common to all implementations
00105 //
00106 XrdSysMutex   PollPipe;
00107 struct pollfd PipePoll;
00108 int           CmdFD;      // FD to send PipeData commands
00109 int           ReqFD;      // FD to recv PipeData requests
00110 struct        PipeData {union {XrdSysSemaphore  *theSem;
00111                                struct {int fd;
00112                                        int ent;} Arg;
00113                               } Parms;
00114                         enum cmd {EnFD, DiFD, RmFD, Post};
00115                         cmd req;
00116                        };
00117               PipeData ReqBuff;
00118 char         *PipeBuff;
00119 int           PipeBlen;
00120 
00121 // The following are statistical counters each implementation must maintain
00122 //
00123            int         numEnabled;     // Count of Enable() calls
00124            int         numEvents;      // Count of poll fd's dispatched
00125            int         numInterrupts;  // Number of interrupts (e.g., signals)
00126 
00127 private:
00128 
00129 static     XrdSysMutex  doingAttach;
00130            int          numAttached;    // Number of fd's attached to poller
00131 };
00132 #endif