version 1.2, 2015/04/20 18:10:35
|
version 1.3, 2015/04/20 18:20:34
|
|
|
| |
BEGIN_EXTERNC | BEGIN_EXTERNC |
| |
#define SELECTOR_ADD (1 << 0) |
#define SELECTOR_ADD 0x1 |
#define SELECTOR_READ (1 << 1) |
#define SELECTOR_READ 0x2 |
#define SELECTOR_WRITE (1 << 2) |
#define SELECTOR_WRITE 0x4 |
#define SELECTOR_EXCEPTION (1 << 3) |
#define SELECTOR_EXCEPTION 0x8 |
#define SELECTOR_TIMEOUT (1 << 4) |
#define SELECTOR_TIMEOUT 0x10 |
#define SELECTOR_REMOVE (1 << 5) |
#define SELECTOR_REMOVE 0x20 |
#define SELECTOR_DESTROY (1 << 6) |
#define SELECTOR_DESTROY 0x40 |
#define SELECTOR_IGNORE_READ_OVERLOAD (1 << 7) |
|
| |
typedef struct _Selector Selector; | typedef struct _Selector Selector; |
typedef struct _Handler Handler; | typedef struct _Handler Handler; |
|
|
Handler* prev; | Handler* prev; |
Sock sock; | Sock sock; |
MI_Uint32 mask; | MI_Uint32 mask; |
/* time when selector gets 'timeout' event - typically Time_Now() + ttl-in-usec; |
/* time when selector gets 'timeout' event - typically PAL_Time() + ttl-in-usec; |
'0' means 'ignore me' */ | '0' means 'ignore me' */ |
MI_Uint64 fireTimeoutAt; | MI_Uint64 fireTimeoutAt; |
MI_Boolean (*callback)(Selector*, Handler*, MI_Uint32 mask, MI_Uint64 currentTimeUsec); | MI_Boolean (*callback)(Selector*, Handler*, MI_Uint32 mask, MI_Uint64 currentTimeUsec); |
|
|
*/ | */ |
MI_Result Selector_Run( | MI_Result Selector_Run( |
Selector* self, | Selector* self, |
MI_Uint64 timeoutUsec); |
MI_Uint64 timeoutUsec, |
|
MI_Boolean noReadsMode ); |
|
|
|
int Selector_IsSelectorThread(Selector* self, ThreadID *id); |
| |
/* Informs selector's Run method that it should exit normaly. | /* Informs selector's Run method that it should exit normaly. |
Funciton is safe for calling from signal hanlder */ | Funciton is safe for calling from signal hanlder */ |
MI_Result Selector_StopRunning( | MI_Result Selector_StopRunning( |
Selector* self); | Selector* self); |
|
MI_Result Selector_StopRunningNoReadsMode( |
|
Selector* self); |
| |
/* Wakes up selector's thread | /* Wakes up selector's thread |
Typical usage is to recalculate timeouts on handlers | Typical usage is to recalculate timeouts on handlers |
when selector's Run is running in different thread */ | when selector's Run is running in different thread */ |
MI_Result Selector_Wakeup( | MI_Result Selector_Wakeup( |
Selector* self); |
_In_ Selector* self, |
|
MI_Boolean retryDispatching ); |
| |
/* | /* |
* This function guaranties that callback is called in 'Run'/'IO' thread context, | * This function guaranties that callback is called in 'Run'/'IO' thread context, |
|
|
Message* message); | Message* message); |
| |
/* | /* |
Informs selector that new Instance was created; |
|
Selector keeps track of number of Instances |
|
so it can implement back-pressure (primitive) by |
|
disabling read from oop and blocking other-thread providers |
|
*/ |
|
void Selector_NewInstanceCreated( |
|
Selector* self, |
|
Message* msg); |
|
|
|
|
|
/* |
|
Verifies if selector is in 'stressed' mode |
|
and too many instance are alive now |
|
*/ |
|
MI_Boolean Selector_IsStressed( |
|
Selector* self); |
|
|
|
|
|
/* |
|
Sets flag 'allowEmptySelector' to allow | Sets flag 'allowEmptySelector' to allow |
'run' call on empty selector | 'run' call on empty selector |
*/ | */ |