mirror of
https://github.com/libevent/libevent.git
synced 2025-01-31 09:12:55 +08:00
Merge remote-tracking branch 'origin/patches-2.0'
This commit is contained in:
commit
89def5391e
61
kqueue.c
61
kqueue.c
@ -50,8 +50,10 @@
|
|||||||
* easy way to tell them apart via autoconf, so we need to use OS macros. */
|
* easy way to tell them apart via autoconf, so we need to use OS macros. */
|
||||||
#if defined(_EVENT_HAVE_INTTYPES_H) && !defined(__OpenBSD__) && !defined(__FreeBSD__) && !defined(__darwin__) && !defined(__APPLE__)
|
#if defined(_EVENT_HAVE_INTTYPES_H) && !defined(__OpenBSD__) && !defined(__FreeBSD__) && !defined(__darwin__) && !defined(__APPLE__)
|
||||||
#define PTR_TO_UDATA(x) ((intptr_t)(x))
|
#define PTR_TO_UDATA(x) ((intptr_t)(x))
|
||||||
|
#define INT_TO_UDATA(x) ((intptr_t)(x))
|
||||||
#else
|
#else
|
||||||
#define PTR_TO_UDATA(x) (x)
|
#define PTR_TO_UDATA(x) (x)
|
||||||
|
#define INT_TO_UDATA(x) ((void*)(x))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "event-internal.h"
|
#include "event-internal.h"
|
||||||
@ -168,6 +170,8 @@ kq_sighandler(int sig)
|
|||||||
/* Do nothing here */
|
/* Do nothing here */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define ADD_UDATA 0x30303
|
||||||
|
|
||||||
static void
|
static void
|
||||||
kq_setup_kevent(struct kevent *out, evutil_socket_t fd, int filter, short change)
|
kq_setup_kevent(struct kevent *out, evutil_socket_t fd, int filter, short change)
|
||||||
{
|
{
|
||||||
@ -177,6 +181,9 @@ kq_setup_kevent(struct kevent *out, evutil_socket_t fd, int filter, short change
|
|||||||
|
|
||||||
if (change & EV_CHANGE_ADD) {
|
if (change & EV_CHANGE_ADD) {
|
||||||
out->flags = EV_ADD;
|
out->flags = EV_ADD;
|
||||||
|
/* We set a magic number here so that we can tell 'add'
|
||||||
|
* errors from 'del' errors. */
|
||||||
|
out->udata = INT_TO_UDATA(ADD_UDATA);
|
||||||
if (change & EV_ET)
|
if (change & EV_ET)
|
||||||
out->flags |= EV_CLEAR;
|
out->flags |= EV_CLEAR;
|
||||||
#ifdef NOTE_EOF
|
#ifdef NOTE_EOF
|
||||||
@ -315,27 +322,47 @@ kq_dispatch(struct event_base *base, struct timeval *tv)
|
|||||||
int which = 0;
|
int which = 0;
|
||||||
|
|
||||||
if (events[i].flags & EV_ERROR) {
|
if (events[i].flags & EV_ERROR) {
|
||||||
/*
|
switch (events[i].data) {
|
||||||
* Error messages that can happen, when a delete fails.
|
|
||||||
* EBADF happens when the file descriptor has been
|
/* Can occur on delete if we are not currently
|
||||||
* closed,
|
* watching any events on this fd. That can
|
||||||
* ENOENT when the file descriptor was closed and
|
* happen when the fd was closed and another
|
||||||
* then reopened.
|
* file was opened with that fd. */
|
||||||
* EINVAL for some reasons not understood; EINVAL
|
case ENOENT:
|
||||||
* should not be returned ever; but FreeBSD does :-\
|
/* Can occur for reasons not fully understood
|
||||||
* An error is also indicated when a callback deletes
|
* on FreeBSD. */
|
||||||
* an event we are still processing. In that case
|
case EINVAL:
|
||||||
* the data field is set to ENOENT.
|
|
||||||
*/
|
|
||||||
if (events[i].data == EBADF ||
|
|
||||||
events[i].data == EINVAL ||
|
|
||||||
events[i].data == ENOENT)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
/* Can occur on a delete if the fd is closed. Can
|
||||||
|
* occur on an add if the fd was one side of a pipe,
|
||||||
|
* and the other side was closed. */
|
||||||
|
case EBADF:
|
||||||
|
/* These two can occur on an add if the fd was one side
|
||||||
|
* of a pipe, and the other side was closed. */
|
||||||
|
case EPERM:
|
||||||
|
case EPIPE:
|
||||||
|
/* Report read events, if we're listening for
|
||||||
|
* them, so that the user can learn about any
|
||||||
|
* add errors. (If the operation was a
|
||||||
|
* delete, then udata should be cleared.) */
|
||||||
|
if (events[i].udata) {
|
||||||
|
/* The operation was an add:
|
||||||
|
* report the error as a read. */
|
||||||
|
which |= EV_READ;
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
/* The operation was a del:
|
||||||
|
* report nothing. */
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Other errors shouldn't occur. */
|
||||||
|
default:
|
||||||
errno = events[i].data;
|
errno = events[i].data;
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
} else if (events[i].filter == EVFILT_READ) {
|
||||||
if (events[i].filter == EVFILT_READ) {
|
|
||||||
which |= EV_READ;
|
which |= EV_READ;
|
||||||
} else if (events[i].filter == EVFILT_WRITE) {
|
} else if (events[i].filter == EVFILT_WRITE) {
|
||||||
which |= EV_WRITE;
|
which |= EV_WRITE;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user