00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
00031
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
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