Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

MNSelector.h

Go to the documentation of this file.
00001 /* Copyright (C) 2000 KOM/Darmstadt University of Technology 00002 * 00003 * You are allowed to use all other parts of the code under the following terms: 00004 * 00005 * For non-commercial use, code may be used in unmodified form provided 00006 * that this copyright notice and this permission notice appear in 00007 * supporting documentation. 00008 * 00009 * This software is provided "as is" and without any express or implied 00010 * warranties, including, without limitation, the implied warranty of 00011 * fitness for a particular purpose. 00012 * 00013 * The code may be subjected to the GNU General Public License, Version 2, 00014 * and re-distributed under the terms of this license. 00015 * As a special exception, permission is granted to link this code 00016 * with the Qt library and distribute executables, as long as you 00017 * follow the requirements of the GNU GPL in regard to all of the 00018 * software in the executable aside from Qt. 00019 * 00020 * Commercial use other than under the terms of the GNU General Public 00021 * License is allowed only after express negotiation of conditions 00022 * with the authors. 00023 */ 00024 #ifndef MN_SELECTOR_H 00025 #define MN_SELECTOR_H 00026 00027 #define max_fd_find(i,j) (((i)>(j)) ? (i) : (j)) 00028 00029 /************************************************************* 00030 * Name: MNSelector 00031 * Short: takes up to all socket objects to wait for 00032 */ 00033 00034 #include <assert.h> 00035 #include <sys/time.h> 00036 00037 #include "dictionary.h" 00038 #include "MNSocketBase.h" 00039 #include "MNMutex.h" 00040 #include "MNTimerEntry.h" 00041 #include "MNTimerCall.h" 00042 #include "MNValid.h" 00043 00044 /* An bugfix for an annoying define in net/net_globals.h on AIX */ 00045 #ifdef wakeup 00046 #undef wakeup 00047 #endif 00048 00049 class MNTimer; 00050 class TimerCallBase; 00051 class AutonomousTimer; 00052 00053 class MNSelector 00054 { 00055 DECLARE_VALID 00056 00057 private: 00058 friend class MNTimer; 00059 friend class AutonomousTimer; 00060 00061 typedef MNSocketBase* MNSocketBasePtr; 00062 typedef dictionary<int,MNSocketBasePtr> FdMap; 00063 00064 FdMap _fd_read_entries; 00065 FdMap _fd_write_entries; 00066 MNMutex _fd_mutex; 00067 00068 TimerMap _timer_entries; 00069 00075 int private_init( fd_set& read_set, fd_set& write_set, fd_set& except_set ); 00076 00077 public: 00090 MNSelector( bool notifiable ); 00091 virtual ~MNSelector( ); 00092 00093 void select( ); 00094 00112 void insert( MNSocketBase* socketptr, 00113 bool threaded, 00114 const char* caller, 00115 u_int32_t set = MNSelector::READSET); 00116 00117 void remove_fd ( int fd, u_int32_t set = MNSelector::BOTHSETS ); 00118 void remove_fd ( MNSocketBase* socketptr ); 00119 00120 bool insert_abs_timer( void* data, 00121 TimerCallBase* timerptr, 00122 const struct timeval& timeout, 00123 const char* owner ); 00124 bool insert_rel_timer( void* data, 00125 TimerCallBase* timerptr, 00126 const struct timeval& timeout, 00127 const char* owner ); 00128 bool insert_periodic_timer( void* data, 00129 TimerCallBase* timerptr, 00130 const struct timeval& timeout, 00131 const char* owner ); 00132 bool cancel_timer( TimerCallBase* timerptr ); 00133 void cancel_all_timers( ); 00134 00135 public: 00137 static const bool DontWakeup = false; 00138 00140 static const bool Wakeup = true; 00141 00143 static const u_int32_t READSET = 0; 00144 static const u_int32_t WRITESET = 1; 00145 static const u_int32_t BOTHSETS = 2; 00146 00147 private: 00148 enum RW 00149 { 00150 Read = 0, 00151 Write = 1, 00152 Both = 2 00153 }; 00154 00155 int _notepipe[Both]; 00156 bool _notifiable; 00157 00158 public: 00163 void wakeup( ); 00164 00165 bool notifiable( ) const; 00166 00167 private: 00175 void private_debug_find_bad_fd( ); 00176 }; 00177 00178 #endif /* MN_SELECTOR_H */

Generated on Sun Mar 6 13:35:49 2005 for Komssys by doxygen 1.3.8