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-AC02-76-SFO0515 with the Department of Energy */ 00010 /* */ 00011 /* This file is part of the XRootD software suite. */ 00012 /* */ 00013 /* XRootD is free software: you can redistribute it and/or modify it under */ 00014 /* the terms of the GNU Lesser General Public License as published by the */ 00015 /* Free Software Foundation, either version 3 of the License, or (at your */ 00016 /* option) any later version. */ 00017 /* */ 00018 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 00019 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 00020 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 00021 /* License for more details. */ 00022 /* */ 00023 /* You should have received a copy of the GNU Lesser General Public License */ 00024 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 00025 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 00026 /* */ 00027 /* The copyright holder's institutional names and contributor's names may not */ 00028 /* be used to endorse or promote products derived from this software without */ 00029 /* specific prior written permission of the institution or contributor. */ 00030 /******************************************************************************/ 00031 00032 #include <sys/poll.h> 00033 #include "XrdSys/XrdSysPthread.hh" 00034 00035 #define XRD_NUMPOLLERS 3 00036 00037 class XrdPollInfo; 00038 class XrdSysSemaphore; 00039 00040 class XrdPoll 00041 { 00042 public: 00043 00044 // Attach() is called when a new link needs to be assigned to a poller 00045 // 00046 static int Attach(XrdPollInfo &pInfo); 00047 00048 // Detach() is called when a link is being discarded 00049 // 00050 static void Detach(XrdPollInfo &pInfo); 00051 00052 // Disable() is called when we need to mask interrupts from a link 00053 // 00054 virtual void Disable(XrdPollInfo &pInfo, const char *etxt=0) = 0; 00055 00056 // Enable() is called when we want to receive interrupts from a link 00057 // 00058 virtual int Enable(XrdPollInfo &pInfo) = 0; 00059 00060 // Finish() is called to allow a link to gracefully terminate when scheduled 00061 // 00062 static int Finish(XrdPollInfo &pInfo, const char *etxt=0); //Implementation supplied 00063 00064 // Poll2Text() converts bits in an revents item to text 00065 // 00066 static char *Poll2Text(short events); // Implementation supplied 00067 00068 // Setup() is called at config time to perform poller configuration 00069 // 00070 static int Setup(int numfd); // Implementation supplied 00071 00072 // Start() is called via a thread for each poller that was created 00073 // 00074 virtual void Start(XrdSysSemaphore *syncp, int &rc) = 0; 00075 00076 // Stats() is called to provide statistics on polling 00077 // 00078 static int Stats(char *buff, int blen, int do_sync=0); 00079 00080 // Identification of the thread handling this object 00081 // 00082 int PID; // Poller ID 00083 pthread_t TID; // Thread ID 00084 00085 // The following table reference the pollers in effect 00086 // 00087 static XrdPoll *Pollers[XRD_NUMPOLLERS]; 00088 00089 XrdPoll(); 00090 virtual ~XrdPoll() {} 00091 00092 protected: 00093 00094 static const char *TraceID; // For tracing 00095 00096 // Gets the next request on the poll pipe. This is common to all implentations. 00097 // 00098 int getRequest(); // Implementation supplied 00099 00100 // Exclude() called to exclude a link from a poll set 00101 // 00102 virtual void Exclude(XrdPollInfo &pInfo) = 0; 00103 00104 // Include() called to include a link in a poll set 00105 // 00106 virtual int Include(XrdPollInfo &pInfo) = 0; 00107 00108 // newPoller() called to get a new poll object at initialization time 00109 // Even though static, an implementation must be supplied. 00110 // 00111 static XrdPoll *newPoller(int pollid, int numfd) /* = 0 */; 00112 00113 // The following is common to all implementations 00114 // 00115 XrdSysMutex PollPipe; 00116 struct pollfd PipePoll; 00117 int CmdFD; // FD to send PipeData commands 00118 int ReqFD; // FD to recv PipeData requests 00119 struct PipeData {union {XrdSysSemaphore *theSem; 00120 struct {int fd; 00121 int ent;} Arg; 00122 } Parms; 00123 enum cmd {EnFD, DiFD, RmFD, Post}; 00124 cmd req; 00125 }; 00126 PipeData ReqBuff; 00127 char *PipeBuff; 00128 int PipeBlen; 00129 00130 // The following are statistical counters each implementation must maintain 00131 // 00132 int numEnabled; // Count of Enable() calls 00133 int numEvents; // Count of poll fd's dispatched 00134 int numInterrupts; // Number of interrupts (e.g., signals) 00135 00136 private: 00137 00138 static XrdSysMutex doingAttach; 00139 int numAttached; // Number of fd's attached to poller 00140 }; 00141 #endif