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 //          $Id: XrdPoll.hh 28902 2009-06-11 12:36:21Z ganis $
00013 
00014 #include <sys/poll.h>
00015 #include "XrdSys/XrdSysPthread.hh"
00016 
00017 #define XRD_NUMPOLLERS 3
00018 
00019 class XrdLink;
00020 class XrdSysSemaphore;
00021   
00022 class XrdPoll
00023 {
00024 public:
00025 
00026 // Attach() is called when a new link needs to be assigned to a poller
00027 //
00028 static  int   Attach(XrdLink *lp);    // Implementation supplied
00029 
00030 // Detach() is called when a link is being discarded
00031 //
00032 static  void  Detach(XrdLink *lp);   //  Implementation supplied
00033 
00034 // Disable() is called when we need to mask interrupts from a link
00035 //
00036 virtual void  Disable(XrdLink *lp, const char *etxt=0) = 0;
00037 
00038 // Enable() is called when we want to receive interrupts from a link
00039 //
00040 virtual int   Enable(XrdLink *lp)  = 0;
00041 
00042 // Finish() is called to allow a link to gracefully terminate when scheduled
00043 //
00044 static  int   Finish(XrdLink *lp, const char *etxt=0); //Implementation supplied
00045 
00046 // Poll2Text() converts bits in an revents item to text
00047 //
00048 static  char *Poll2Text(short events); // Implementation supplied
00049 
00050 // Setup() is called at config time to perform poller configuration
00051 //
00052 static  int   Setup(int numfd);        // Implementation supplied
00053 
00054 // Start() is called via a thread for each poller that was created
00055 //
00056 virtual void  Start(XrdSysSemaphore *syncp, int &rc) = 0;
00057 
00058 // Stats() is called to provide statistics on polling
00059 //
00060 static  int   Stats(char *buff, int blen, int do_sync=0);
00061 
00062 // Identification of the thread handling this object
00063 //
00064            int         PID;       // Poller ID
00065            pthread_t   TID;       // Thread ID
00066 
00067 // The following table reference the pollers in effect
00068 //
00069 static     XrdPoll   *Pollers[XRD_NUMPOLLERS];
00070 
00071            XrdPoll();
00072 virtual   ~XrdPoll() {}
00073 
00074 protected:
00075 
00076 static     const char *TraceID;                  // For tracing
00077 
00078 // Gets the next request on the poll pipe. This is common to all implentations.
00079 //
00080            int         getRequest();             // Implementation supplied
00081 
00082 // Exclude() called to exclude a link from a poll set
00083 //
00084 virtual    void        Exclude(XrdLink *lp) = 0;
00085 
00086 // Include() called to include a link in a poll set
00087 //
00088 virtual    int         Include(XrdLink *lp) = 0;
00089 
00090 // newPoller() called to get a new poll object at initialization time
00091 //             Even though static, an implementation must be supplied.
00092 //
00093 static     XrdPoll   *newPoller(int pollid, int numfd)    /* = 0 */;
00094 
00095 // The following is common to all implementations
00096 //
00097 XrdSysMutex   PollPipe;
00098 struct pollfd PipePoll;
00099 int           CmdFD;      // FD to send PipeData commands
00100 int           ReqFD;      // FD to recv PipeData requests
00101 struct        PipeData {union {XrdSysSemaphore  *theSem;
00102                                struct {int fd;
00103                                        int ent;} Arg;
00104                               } Parms;
00105                         enum cmd {EnFD, DiFD, RmFD, Post};
00106                         cmd req;
00107                        };
00108               PipeData ReqBuff;
00109 char         *PipeBuff;
00110 int           PipeBlen;
00111 
00112 // The following are statistical counters each implementation must maintain
00113 //
00114            int         numEnabled;     // Count of Enable() calls
00115            int         numEvents;      // Count of poll fd's dispatched
00116            int         numInterrupts;  // Number of interrupts (e.g., signals)
00117 
00118 private:
00119 
00120 static     XrdSysMutex  doingAttach;
00121            int          numAttached;    // Number of fd's attached to poller
00122 };
00123 #endif

Generated on Tue Jul 5 14:46:15 2011 for ROOT_528-00b_version by  doxygen 1.5.1