📄 ndet.h
字号:
extern ndet_check_sig(); /* Returns 0 if all OK else -1 and sets notify_errno to NOTIFY_BAD_SIGNAL (int sig) */extern ndet_check_mode(); /* Returns 0 if all OK else -1 and sets notify_errno to NOTIFY_INVAL. Sets type_ptr if not null. (Notify_signal_mode mode, NTFY_TYPE *type_ptr) */extern ndet_check_which(); /* Turn itimer which into type. Returns 0 if all OK else -1 and sets notify_errno to NOTIFY_INVAL. Sets type_ptr if not null. (int which, NTFY_TYPE *type_ptr) */#define ndet_tv_equal(_a, _b) \ (_a.tv_sec == _b.tv_sec && _a.tv_usec == _b.tv_usec)#define ndet_tv_polling(tv) ndet_tv_equal((tv), NOTIFY_POLLING_ITIMER.it_value)extern struct timeval ndet_tv_subt(); /* Subtracts b from a. Will round down any NOTIFY_POLLING_ITIMER.it_value results to {0,0}. This is to prevent the notifier from generating a polling timer (struct timeval a, b) */extern struct timeval ndet_tv_min(); /* Find min of b and a. (struct timeval a, b) */extern struct timeval ndet_real_min(); /* Figure the interval that has transpired since this real interval timer has been set. The difference between how much time the timer wants to wait and how long it has waited is the amount of time left to wait. The time left to wait is returned. (NTFY_ITIMER *ntfy_itimer, struct timeval current_tv) */extern struct timeval ndet_virtual_min(); /* Update the interval until expiration by subtracting the amount of time on the process interval timer (current_tv) from the value of the process interval timer when it was last looked at by this client (ntfy_itimer->set_tv). Return the amount of time that this virtual interval timer has to go before expiration (ntfy_itimer->itimer.it_value). Need to update ntfy_itimer->set_tv with this value after calling ndet_virtual_min. (NTFY_ITIMER *ntfy_itimer, struct timeval current_tv) */extern void ndet_reset_itimer_set_tv();/* Reset ntfy_itimer->set_tv based on type (NTFY_CONDITION *condition) *//* * NDET_ENUM_SEND is used to send the results of select around to conditions. */typedef struct ndet_enum_send { fd_set ibits; /* Input devices selected */ fd_set obits; /* Output devices selected */ fd_set ebits; /* Exception devices selected */ u_int sigs; /* Signals to process */ NTFY_WAIT3_DATA *wait3; /* Results of wait3 system call */ struct timeval current_tv; /* NTFY_REAL_ITIMER time-of-day (now) NTFY_VIRTUAL_ITIMER current itimer it_value */} NDET_ENUM_SEND;/* * When recomputing itimers, NDET_ENUM_ITIMER is used to pass the context * for the real or virtual itimer around. */ typedef struct ndet_enum_itimer { int enqueued; /* Not zero if enqd notification */ NTFY_TYPE type; /* One of NTFY_*_ITIMER */ u_int polling_bit; /* One of NDET_*_POLL */ int signal; /* SIGALRM | SIGVTALRM */ int which; /* VIRTUAL_ITIMER | REAL_ITIMER */ struct timeval (*min_func)(); /* Returns the interval that a given itimer needs to wait until expiration (virtual itimer resets set_time) */ Notify_value (*expire_func)();/* Called when itimer expiration detected */ struct timeval current_tv; /* Real is time-of-day, virtual is current virtual itimer value */ struct timeval min_tv; /* Global min of min_func return value*/} NDET_ENUM_ITIMER;extern struct timeval ndet_virtual_min();extern struct timeval ndet_real_min();extern void ndet_update_virtual_itimer();/* Some virtual itimer related condition has changed. Update all virtual itimers. Determine minimum wait and set virtual itimer. Enable (disable) notifier auto signal catching of SIGVTALRM. (int send) */extern void ndet_update_real_itimer(); /* Some real itimer related condition has changed. Determine minimum wait and set real itimer. Enable(disable) notifier auto signal catching of SIGALRM. (int send) */extern NTFY_ENUM ndet_fd_send(); /* Enqueue notifications for any fds in (NDET_ENUM_SEND *) context. (NTFY_CLIENT *client, NTFY_CONDITION *condition, NTFY_ENUM_DATA context) */extern void ndet_set_event_processing();/* Called from dispatcher to tell detector that nclient is in the process of handling a client event (on == 1) or done handling a client event (on == 0). (Notify_client nclient, int on) */#ifdef COMMENT********************** Interval Timer Algorithms *************************For both types of interval timers:1) When an interval timer expires for a client, the reset value is usedto set the interval value.2) The smallest interval of all clients is used to reset the processinterval timer.3) Before recomputing a process timer, use the TIME_DIF (see below)to update it_value in all the clients. Any it_values <= zero are sentnotifications.4) When a process timer expires, simply recomputing the process timerhas the side effect of sending notifications.Note: Polling is inefficient if not special cased. Polling is separatefrom interval timer computation. Polling is implemented as somethingrelated to the select timer.4) Caution: a) Signals being received while recomputing interval causing duplicate notifications. b) Granularity of very short intervals may cause overlap of notification and determining the next one.For process virtual time interval timers TIME_DIF is the value usedto set the process timer.Computation of real time interval timers differs from process virtualtime interval timers in that the real timer interval timer must be exactenough so that if a client sets it to be the difference between now and5:00am that he would be notifier at 5:00am. To avoid cummulative delayerrors, we make real time interval timers relative to the time of day atwhich they were set. Thus, when setting a client timer(ntfy_set_itimer_func or resetting from it_value), note the tod(time-of-day) and the original it_value. TIME_DIF is the differencefrom the current tod and the original tod. The original it_value-TIME_DIF gives the current it_value.********************** Handling Supplementary Signals ********************In notification loop1) Find fd that is async.2) Set SIGIO signal catcher with ndet_sigio as function.3) Ndet_sigio will search all conditions in its client for fds which matchndet_fasync_mask.4) Any that match have a FIOCNREAD done to see if any input for that fd.5) Send notification if so, else ignore.********************** Clients Considerations ****************************Changing a condition during a notification:1) Changes can come any time, synchronously or asynchronously,as long as they are notification derived, i.e., a client didn'tcatch a signal and call the notifier himself. 2) Condition changes affect what will be waited on next time throughthe notication loop. If you remove a condition asynchronously thenit wouldn't be notified. If you add a condition asynchronously thathappens to be selected on this time already then you may get anotification this time around the notication loop instead of next time.3) Multiple changes to the same condition are applied immediately, i.e.,the last change that the notifier got will be the current one.4) A notify_post_destroy or notify_die command applies immediately.Callers of these routines should do so during synchronous processing.To do so otherwise is an error (NOTIFY_CANT_INTERRUPT). This is becausethe notifier refuses to call out to a client that may be in an unsafecondition unless the client has stated explicitely that it willworry about safety himself, e.g., asynchronously signals andimmediate client events.#endif COMMENT#endif NDET_DEFINED
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -