📄 ndet.h
字号:
/* @(#)ndet.h 1.1 92/07/30 SMI *//* * Copyright (c) 1985, 1988 by Sun Microsystems, Inc. *//* * Ndet.h - Private header file for the detector part of the notifier. * The detector is responsible for noticing the occurrence of UNIX * events. It maintains a complete list of clients that are awaiting * notification. It maintains a per client list of conditions that the * client is awaiting. */#ifndef NDET_DEFINED#define NDET_DEFINED#ifdef COMMENT********************** Detector Loop Notes ****************************Here is some notes on the detector loop:1) Any time that a notification changes (new, added, removed, modified),the appropriate "changed" constant is ored into ndet_flags (see below). To determine the things that the notifier needs to ask UNIXto watch for (fd activity, signals, itimers) requires scanningall clients and notifications. Comparing the result of this scanwith what the notifier is already watching for determines what workhas to be done to change what UNIX is doing.2) A cycle of the notification loop can be entered in a variety of ways.a) Notify_start can be called by the top level of the application.b) When select is called, if notifications are being dispatched thena real select system call is made. Otherwise, a private notifierclient is generated that sets conditions equivalent to the select'sarguments. Result bit masks and itimer expired flags are initialized.Notify_start is then called. If any of the select client's routinesare called, result bit masks and/or itimer expired flags are set.In addition, notify_stop is called. When notify_start returns, itserror code, errno, the result bit masks and/or itimer expired flagsare used to generate return values.c) When read is called, if notifications are being dispatched thena real read system call is made. Otherwise, a private notifierclient is generated that sets an input pending condition for the readfd. A input pending flag is initialized. Notify_start is then called.If the read client's input pending routine is called, the inputpending flag is set. In addition, notify_stop is called. Whennotify_stop returns, its error code, errno and the input pending flagare used to figure out if a real read system call is to be done.If so, a real read system call is done and the results returned.********************** Public Interface Supporting *********************The public programming interface that the detector supports follows:notify_set_input_funcnotify_set_output_funcnotify_set_exception_funcnotify_set_itimer_funcnotify_set_signal_funcnotify_set_wait3_funcnotify_set_destroy_funcnotify_set_event_funcnotify_set_prioritizer_funcnotify_get_itimer_valuenotify_post_eventnotify_post_destroynotify_veto_destroynotify_startnotify_stopnotify_dienotify_removefcntlreadselectnotify_get_input_funcnotify_get_output_funcnotify_get_exception_funcnotify_get_itimer_funcnotify_get_signal_funcnotify_get_wait3_funcnotify_get_destroy_funcnotify_get_event_funcnotify_get_prioritizer_func#endif COMMENT/* * The detector uses ndet_/NDET_ name prefices. *//* * Detector global data */extern u_int ndet_flags; /* Flags */#define NDET_STOP 0x01 /* Ntfy_stop called */#define NDET_FD_CHANGE 0x02 /* A fd condition changed */#define NDET_SIGNAL_CHANGE 0x04 /* A signal condition changed */#define NDET_REAL_CHANGE 0x08 /* A real itimer condition changed */#define NDET_VIRTUAL_CHANGE 0x10 /* A virtual itimer condition changed */#define NDET_WAIT3_CHANGE 0x20 /* A wait3 condition changed */#define NDET_DISPATCH 0x40 /* Calling ndis_dispatch (used to know if should do real or notifier version of read and select) */#define NDET_REAL_POLL 0x80 /* Real itimer wants to poll, invalid if ndet_flags & NDET_REAL_CHANGE */#define NDET_VIRTUAL_POLL 0x100 /* Virtual itimer wants to poll, invalid if ndet_flags & NDET_VIRTUAL_CHANGE*/#define NDET_POLL (NDET_REAL_POLL|NDET_VIRTUAL_POLL) /* Do polling in select */#define NDET_INTERRUPT 0x200 /* Set when handling a signal interrupt so that know not to go to system heap */#define NDET_STARTED 0x400 /* In ntfy_start */#define NDET_EXIT_SOON 0x800 /* Notifier auto SIGTERM triggered, exit(1) after finish dispatch */#define NDET_STOP_ON_SIG 0x1000 /* Notifier select client wants to break if get a signal during real select */#define NDET_VETOED 0x2000 /* Notify_veto_destroy called */#define NDET_ITIMER_ENQ 0x4000 /* Itimer notification enqueued */#define NDET_NO_DELAY 0x8000 /* Caller of notify_start wants single time around the loop */#define NDET_DESTROY_CHANGE 0x10000 /* A destroy condition changed */#define NDET_CONDITION_CHANGE (NDET_FD_CHANGE|NDET_SIGNAL_CHANGE|\ NDET_REAL_CHANGE|NDET_VIRTUAL_CHANGE|NDET_WAIT3_CHANGE|NDET_DESTROY_CHANGE) /* Combination of condition changes */extern NTFY_CLIENT *ndet_clients; /* Active clients */extern NTFY_CLIENT *ndet_client_latest;/* Latest Notify_client=>NTFY_CLIENT conversion success: for fast lookup (nulled when client removed) */extern fd_set ndet_fndelay_mask; /* Mask of non-blocking read fds (maintained by fcntl) */extern fd_set ndet_fasync_mask; /* Mask of fds that generate SIGIO when data ready (maintained by fcntl) */extern fd_set ndet_ibits, ndet_obits, ndet_ebits; /* Select bit masks (invalid if ndet_flags & NDET_FD_CHANGE) */extern struct timeval ndet_polling_tv;/* Tv with select type polling value */extern u_int ndet_sigs_auto; /* Bits that indicate which signals the notifier is automatically catching (SIGIO, SIGURG, SIGCHLD, SIGTERM, SIGALRM, SIGVTALRM) */extern void ndet_toggle_auto(); /* When some condition that the notifier is interested in changes, call this to adjust ndet_sigs_auto (TBD reword) (u_int obld_bits, sig) */extern Notify_value ndet_auto_sig_func();/* (Notify_client nclient, int signal, Notify_signal_mode) */extern Notify_client ndet_auto_nclient;/* Private notifier client for auto signal handling */extern NTFY_ENUM ndet_auto_sig_send(); /* Tell auto sig manager that one of its condition has occurred (NTFY_CLIENT *client, NTFY_CONDITION *condition, NTFY_ENUM_DATA context) */extern u_int ndet_sigs_managing; /* Signals that are managing (invalid if ndet_flags & NDET_SIGNAL_CHANGE) */extern u_int ndet_sigs_received; /* Records signals received */extern void ndet_enable_sig(); /* Call this routine (other than from ndet_fig_sig_change) when you need to make sure that a signal is being caught but don't want to go through the whole process of globally finding out who else needs it. (u_int sig) */extern void ndet_send_delayed_sigs();/* Process any async signal conditions that have may have accumulated during a critical section. */extern Notify_func ndet_set_fd_func(); /* (Notify_client nclient, Notify_func func, int fd NTFY_TYPE type) */extern Notify_func ndet_get_fd_func(); /* (Notify_client nclient, int fd, NTFY_TYPE type) */extern Notify_func ndet_get_func(); /* (Notify_client nclient, NTFY_TYPE type, NTFY_DATA data, int use_data) */extern ndet_check_fd(); /* Returns 0 if all OK else -1 and sets notify_errno to NOTIFY_BADF (int fd) */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -