constify; some windows stuff by mike davis; fix a poll bug

svn:r77
This commit is contained in:
Niels Provos 2003-09-25 03:26:53 +00:00
parent dd0b36ab03
commit e506eaf79e
5 changed files with 33 additions and 11 deletions

20
event.c
View File

@ -67,29 +67,35 @@
#include "event.h" #include "event.h"
#ifdef HAVE_SELECT #ifdef HAVE_SELECT
extern struct eventop selectops; extern const struct eventop selectops;
#endif #endif
#ifdef HAVE_POLL #ifdef HAVE_POLL
extern struct eventop pollops; extern const struct eventop pollops;
#endif
#ifdef HAVE_RTSIG
extern const struct eventop rtsigops;
#endif #endif
#ifdef HAVE_EPOLL #ifdef HAVE_EPOLL
extern struct eventop epollops; extern const struct eventop epollops;
#endif #endif
#ifdef HAVE_WORKING_KQUEUE #ifdef HAVE_WORKING_KQUEUE
extern struct eventop kqops; extern const struct eventop kqops;
#endif #endif
#ifdef WIN32 #ifdef WIN32
extern struct eventop win32ops; extern const struct eventop win32ops;
#endif #endif
/* In order of preference */ /* In order of preference */
struct eventop *eventops[] = { const struct eventop *eventops[] = {
#ifdef HAVE_WORKING_KQUEUE #ifdef HAVE_WORKING_KQUEUE
&kqops, &kqops,
#endif #endif
#ifdef HAVE_EPOLL #ifdef HAVE_EPOLL
&epollops, &epollops,
#endif #endif
#ifdef HAVE_RTSIG
&rtsigops,
#endif
#ifdef HAVE_POLL #ifdef HAVE_POLL
&pollops, &pollops,
#endif #endif
@ -102,7 +108,7 @@ struct eventop *eventops[] = {
NULL NULL
}; };
struct eventop *evsel; const struct eventop *evsel;
void *evbase; void *evbase;
/* Handle signals */ /* Handle signals */

17
event.h
View File

@ -36,6 +36,10 @@
extern "C" { extern "C" {
#endif #endif
#ifdef WIN32
#include <windows.h>
#endif
#define EVLIST_TIMEOUT 0x01 #define EVLIST_TIMEOUT 0x01
#define EVLIST_INSERTED 0x02 #define EVLIST_INSERTED 0x02
#define EVLIST_SIGNAL 0x04 #define EVLIST_SIGNAL 0x04
@ -77,7 +81,12 @@ struct event {
TAILQ_ENTRY (event) ev_signal_next; TAILQ_ENTRY (event) ev_signal_next;
RB_ENTRY (event) ev_timeout_node; RB_ENTRY (event) ev_timeout_node;
#ifdef WIN32
HANDLE ev_fd;
OVERLAPPED overlap;
#else
int ev_fd; int ev_fd;
#endif
short ev_events; short ev_events;
short ev_ncalls; short ev_ncalls;
short *ev_pncalls; /* Allows deletes in callback */ short *ev_pncalls; /* Allows deletes in callback */
@ -91,8 +100,8 @@ struct event {
int ev_flags; int ev_flags;
}; };
#define EVENT_SIGNAL(ev) ev->ev_fd #define EVENT_SIGNAL(ev) (int)ev->ev_fd
#define EVENT_FD(ev) ev->ev_fd #define EVENT_FD(ev) (int)ev->ev_fd
#ifdef _EVENT_DEFINED_TQENTRY #ifdef _EVENT_DEFINED_TQENTRY
#undef TAILQ_ENTRY #undef TAILQ_ENTRY
@ -153,7 +162,11 @@ void event_active(struct event *, int, short);
int event_pending(struct event *, short, struct timeval *); int event_pending(struct event *, short, struct timeval *);
#ifdef WIN32
#define event_initialized(ev) ((ev)->ev_flags & EVLIST_INIT && (ev)->ev_fd != INVALID_HANDLE_VALUE)
#else
#define event_initialized(ev) ((ev)->ev_flags & EVLIST_INIT) #define event_initialized(ev) ((ev)->ev_flags & EVLIST_INIT)
#endif
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -90,7 +90,7 @@ int kq_recalc (void *, int);
int kq_dispatch (void *, struct timeval *); int kq_dispatch (void *, struct timeval *);
int kq_insert (struct kqop *, struct kevent *); int kq_insert (struct kqop *, struct kevent *);
struct eventop kqops = { const struct eventop kqops = {
"kqueue", "kqueue",
kq_init, kq_init,
kq_add, kq_add,

3
poll.c
View File

@ -193,6 +193,9 @@ poll_dispatch(void *arg, struct timeval *tv)
for (i = 0; i < nfds; i++) { for (i = 0; i < nfds; i++) {
res = 0; res = 0;
/* If the file gets closed notify */
if (pop->event_set[i].revents & POLLHUP)
pop->event_set[i].revents = POLLIN|POLLOUT;
if (pop->event_set[i].revents & POLLIN) if (pop->event_set[i].revents & POLLIN)
res = EV_READ; res = EV_READ;
else if (pop->event_set[i].revents & POLLOUT) else if (pop->event_set[i].revents & POLLOUT)

View File

@ -80,7 +80,7 @@ int select_del (void *, struct event *);
int select_recalc (void *, int); int select_recalc (void *, int);
int select_dispatch (void *, struct timeval *); int select_dispatch (void *, struct timeval *);
struct eventop selectops = { const struct eventop selectops = {
"select", "select",
select_init, select_init,
select_add, select_add,