diff options
author | kikht <kikht@yandex-team.ru> | 2022-02-10 16:45:14 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:14 +0300 |
commit | 194cae0e8855b11be2005e1eff12c660c3ee9774 (patch) | |
tree | ed29c437b616690880c017855ebe0be34fdf81a2 /contrib/libs/libevent/kqueue.c | |
parent | 49116032d905455a7b1c994e4a696afc885c1e71 (diff) | |
download | ydb-194cae0e8855b11be2005e1eff12c660c3ee9774.tar.gz |
Restoring authorship annotation for <kikht@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/libs/libevent/kqueue.c')
-rw-r--r-- | contrib/libs/libevent/kqueue.c | 248 |
1 files changed, 124 insertions, 124 deletions
diff --git a/contrib/libs/libevent/kqueue.c b/contrib/libs/libevent/kqueue.c index dfd7751d64..a5ec6d6734 100644 --- a/contrib/libs/libevent/kqueue.c +++ b/contrib/libs/libevent/kqueue.c @@ -27,24 +27,24 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "event2/event-config.h" -#include "evconfig-private.h" - -#ifdef EVENT__HAVE_KQUEUE +#include "evconfig-private.h" +#ifdef EVENT__HAVE_KQUEUE + #include <sys/types.h> -#ifdef EVENT__HAVE_SYS_TIME_H +#ifdef EVENT__HAVE_SYS_TIME_H #include <sys/time.h> #endif #include <sys/queue.h> #include <sys/event.h> -#include <limits.h> +#include <limits.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <errno.h> -#ifdef EVENT__HAVE_INTTYPES_H +#ifdef EVENT__HAVE_INTTYPES_H #include <inttypes.h> #endif @@ -66,12 +66,12 @@ #include "log-internal.h" #include "evmap-internal.h" #include "event2/thread.h" -#include "event2/util.h" +#include "event2/util.h" #include "evthread-internal.h" #include "changelist-internal.h" -#include "kqueue-internal.h" - +#include "kqueue-internal.h" + #define NEVENT 64 struct kqop { @@ -81,7 +81,7 @@ struct kqop { struct kevent *events; int events_size; int kq; - int notify_event_added; + int notify_event_added; pid_t pid; }; @@ -96,8 +96,8 @@ static void kq_dealloc(struct event_base *); const struct eventop kqops = { "kqueue", kq_init, - event_changelist_add_, - event_changelist_del_, + event_changelist_add_, + event_changelist_del_, kq_dispatch, kq_dealloc, 1 /* need reinit */, @@ -212,17 +212,17 @@ kq_build_changes_list(const struct event_changelist *changelist, struct event_change *in_ch = &changelist->changes[i]; struct kevent *out_ch; if (n_changes >= kqop->changes_size - 1) { - int newsize; + int newsize; struct kevent *newchanges; - if (kqop->changes_size > INT_MAX / 2 || - (size_t)kqop->changes_size * 2 > EV_SIZE_MAX / - sizeof(struct kevent)) { - event_warnx("%s: int overflow", __func__); - return (-1); - } - - newsize = kqop->changes_size * 2; + if (kqop->changes_size > INT_MAX / 2 || + (size_t)kqop->changes_size * 2 > EV_SIZE_MAX / + sizeof(struct kevent)) { + event_warnx("%s: int overflow", __func__); + return (-1); + } + + newsize = kqop->changes_size * 2; newchanges = mm_realloc(kqop->changes, newsize * sizeof(struct kevent)); if (newchanges == NULL) { @@ -273,8 +273,8 @@ kq_dispatch(struct event_base *base, struct timeval *tv) int i, n_changes, res; if (tv != NULL) { - ts.tv_sec = tv->tv_sec; - ts.tv_nsec = tv->tv_usec * 1000; + ts.tv_sec = tv->tv_sec; + ts.tv_nsec = tv->tv_usec * 1000; ts_p = &ts; } @@ -284,7 +284,7 @@ kq_dispatch(struct event_base *base, struct timeval *tv) if (n_changes < 0) return -1; - event_changelist_remove_all_(&base->changelist, base); + event_changelist_remove_all_(&base->changelist, base); /* steal the changes array in case some broken code tries to call * dispatch twice at once. */ @@ -346,23 +346,23 @@ kq_dispatch(struct event_base *base, struct timeval *tv) * on FreeBSD. */ case EINVAL: continue; -#if defined(__FreeBSD__) - /* - * This currently occurs if an FD is closed - * before the EV_DELETE makes it out via kevent(). - * The FreeBSD capabilities code sees the blank - * capability set and rejects the request to - * modify an event. - * - * To be strictly correct - when an FD is closed, - * all the registered events are also removed. - * Queuing EV_DELETE to a closed FD is wrong. - * The event(s) should just be deleted from - * the pending changelist. - */ - case ENOTCAPABLE: - continue; -#endif +#if defined(__FreeBSD__) + /* + * This currently occurs if an FD is closed + * before the EV_DELETE makes it out via kevent(). + * The FreeBSD capabilities code sees the blank + * capability set and rejects the request to + * modify an event. + * + * To be strictly correct - when an FD is closed, + * all the registered events are also removed. + * Queuing EV_DELETE to a closed FD is wrong. + * The event(s) should just be deleted from + * the pending changelist. + */ + case ENOTCAPABLE: + continue; +#endif /* Can occur on a delete if the fd is closed. */ case EBADF: @@ -403,19 +403,19 @@ kq_dispatch(struct event_base *base, struct timeval *tv) which |= EV_WRITE; } else if (events[i].filter == EVFILT_SIGNAL) { which |= EV_SIGNAL; -#ifdef EVFILT_USER - } else if (events[i].filter == EVFILT_USER) { - base->is_notify_pending = 0; -#endif +#ifdef EVFILT_USER + } else if (events[i].filter == EVFILT_USER) { + base->is_notify_pending = 0; +#endif } if (!which) continue; if (events[i].filter == EVFILT_SIGNAL) { - evmap_signal_active_(base, events[i].ident, 1); + evmap_signal_active_(base, events[i].ident, 1); } else { - evmap_io_active_(base, events[i].ident, which | EV_ET); + evmap_io_active_(base, events[i].ident, which | EV_ET); } } @@ -445,7 +445,7 @@ static void kq_dealloc(struct event_base *base) { struct kqop *kqop = base->evbase; - evsig_dealloc_(base); + evsig_dealloc_(base); kqop_free(kqop); } @@ -471,13 +471,13 @@ kq_sig_add(struct event_base *base, int nsignal, short old, short events, void * if (kevent(kqop->kq, &kev, 1, NULL, 0, &timeout) == -1) return (-1); - /* We can set the handler for most signals to SIG_IGN and - * still have them reported to us in the queue. However, - * if the handler for SIGCHLD is SIG_IGN, the system reaps - * zombie processes for us, and we don't get any notification. - * This appears to be the only signal with this quirk. */ - if (evsig_set_handler_(base, nsignal, - nsignal == SIGCHLD ? SIG_DFL : SIG_IGN) == -1) + /* We can set the handler for most signals to SIG_IGN and + * still have them reported to us in the queue. However, + * if the handler for SIGCHLD is SIG_IGN, the system reaps + * zombie processes for us, and we don't get any notification. + * This appears to be the only signal with this quirk. */ + if (evsig_set_handler_(base, nsignal, + nsignal == SIGCHLD ? SIG_DFL : SIG_IGN) == -1) return (-1); return (0); @@ -505,76 +505,76 @@ kq_sig_del(struct event_base *base, int nsignal, short old, short events, void * if (kevent(kqop->kq, &kev, 1, NULL, 0, &timeout) == -1) return (-1); - if (evsig_restore_handler_(base, nsignal) == -1) + if (evsig_restore_handler_(base, nsignal) == -1) return (-1); return (0); } - - -/* OSX 10.6 and FreeBSD 8.1 add support for EVFILT_USER, which we can use - * to wake up the event loop from another thread. */ - -/* Magic number we use for our filter ID. */ -#define NOTIFY_IDENT 42 - -int -event_kq_add_notify_event_(struct event_base *base) -{ - struct kqop *kqop = base->evbase; -#if defined(EVFILT_USER) && defined(NOTE_TRIGGER) - struct kevent kev; - struct timespec timeout = { 0, 0 }; -#endif - - if (kqop->notify_event_added) - return 0; - -#if defined(EVFILT_USER) && defined(NOTE_TRIGGER) - memset(&kev, 0, sizeof(kev)); - kev.ident = NOTIFY_IDENT; - kev.filter = EVFILT_USER; - kev.flags = EV_ADD | EV_CLEAR; - - if (kevent(kqop->kq, &kev, 1, NULL, 0, &timeout) == -1) { - event_warn("kevent: adding EVFILT_USER event"); - return -1; - } - - kqop->notify_event_added = 1; - - return 0; -#else - return -1; -#endif -} - -int -event_kq_notify_base_(struct event_base *base) -{ - struct kqop *kqop = base->evbase; -#if defined(EVFILT_USER) && defined(NOTE_TRIGGER) - struct kevent kev; - struct timespec timeout = { 0, 0 }; -#endif - if (! kqop->notify_event_added) - return -1; - -#if defined(EVFILT_USER) && defined(NOTE_TRIGGER) - memset(&kev, 0, sizeof(kev)); - kev.ident = NOTIFY_IDENT; - kev.filter = EVFILT_USER; - kev.fflags = NOTE_TRIGGER; - - if (kevent(kqop->kq, &kev, 1, NULL, 0, &timeout) == -1) { - event_warn("kevent: triggering EVFILT_USER event"); - return -1; - } - - return 0; -#else - return -1; -#endif -} - -#endif /* EVENT__HAVE_KQUEUE */ + + +/* OSX 10.6 and FreeBSD 8.1 add support for EVFILT_USER, which we can use + * to wake up the event loop from another thread. */ + +/* Magic number we use for our filter ID. */ +#define NOTIFY_IDENT 42 + +int +event_kq_add_notify_event_(struct event_base *base) +{ + struct kqop *kqop = base->evbase; +#if defined(EVFILT_USER) && defined(NOTE_TRIGGER) + struct kevent kev; + struct timespec timeout = { 0, 0 }; +#endif + + if (kqop->notify_event_added) + return 0; + +#if defined(EVFILT_USER) && defined(NOTE_TRIGGER) + memset(&kev, 0, sizeof(kev)); + kev.ident = NOTIFY_IDENT; + kev.filter = EVFILT_USER; + kev.flags = EV_ADD | EV_CLEAR; + + if (kevent(kqop->kq, &kev, 1, NULL, 0, &timeout) == -1) { + event_warn("kevent: adding EVFILT_USER event"); + return -1; + } + + kqop->notify_event_added = 1; + + return 0; +#else + return -1; +#endif +} + +int +event_kq_notify_base_(struct event_base *base) +{ + struct kqop *kqop = base->evbase; +#if defined(EVFILT_USER) && defined(NOTE_TRIGGER) + struct kevent kev; + struct timespec timeout = { 0, 0 }; +#endif + if (! kqop->notify_event_added) + return -1; + +#if defined(EVFILT_USER) && defined(NOTE_TRIGGER) + memset(&kev, 0, sizeof(kev)); + kev.ident = NOTIFY_IDENT; + kev.filter = EVFILT_USER; + kev.fflags = NOTE_TRIGGER; + + if (kevent(kqop->kq, &kev, 1, NULL, 0, &timeout) == -1) { + event_warn("kevent: triggering EVFILT_USER event"); + return -1; + } + + return 0; +#else + return -1; +#endif +} + +#endif /* EVENT__HAVE_KQUEUE */ |