Various fixes for Windows.

git-svn-id: svn://svn.code.sf.net/p/libkqueue/code/trunk@496 fb4e3144-bc1c-4b72-a658-5bcd248dd7f7
This commit is contained in:
mheily 2011-04-30 04:19:08 +00:00
parent 0f356c8932
commit 2aff28d85a
3 changed files with 46 additions and 7 deletions

View File

@ -84,6 +84,7 @@ windows_kqueue_init(struct kqueue *kq)
return (-1);
}
#if DEADWOOD
/* Create a handle whose sole purpose is to indicate a synthetic
* IO event. */
kq->kq_synthetic_event = CreateSemaphore(NULL, 0, 1, NULL);
@ -93,7 +94,6 @@ windows_kqueue_init(struct kqueue *kq)
return (-1);
}
#if DEADWOOD
kq->kq_loop = evt_create();
if (kq->kq_loop == NULL) {
dbg_perror("evt_create()");
@ -188,7 +188,6 @@ windows_kevent_copyout(struct kqueue *kq, int nready,
knote_lock(kn);
filt = &kq->kq_filt[~(kn->kev.filter)];
rv = filt->kf_copyout(eventlist, kn, &iocp_buf);
knote_unlock(kn);
if (slowpath(rv < 0)) {
dbg_puts("knote_copyout failed");
/* XXX-FIXME: hard to handle this without losing events */
@ -206,6 +205,8 @@ windows_kevent_copyout(struct kqueue *kq, int nready,
if (eventlist->flags & EV_ONESHOT)
knote_delete(filt, kn); //TODO: Error checking
knote_unlock(kn);
/* If an empty kevent structure is returned, the event is discarded. */
if (fastpath(eventlist->filter != 0)) {
eventlist++;
@ -232,3 +233,33 @@ windows_filter_free(struct kqueue *kq, struct filter *kf)
{
}
int
windows_get_descriptor_type(struct knote *kn)
{
socklen_t slen;
struct stat sb;
int i, lsock;
/*
* Test if the descriptor is a socket.
*/
if (fstat(kn->kev.ident, &sb) == 0) {
dbg_printf("HANDLE %d appears to a be regular file", kn->kev.ident);
kn->kn_flags |= KNFL_REGULAR_FILE;
} else {
/* Assume that the HANDLE is a socket. */
/* TODO: we could do a WSAIoctl and check for WSAENOTSOCK */
/*
* Test if the socket is active or passive.
*/
slen = sizeof(lsock);
lsock = 0;
i = getsockopt(kn->kev.ident, SOL_SOCKET, SO_ACCEPTCONN, (char *) &lsock, &slen);
if (i == 0 && lsock)
kn->kn_flags |= KNFL_PASSIVE_SOCKET;
}
return (0);
}

View File

@ -31,6 +31,8 @@
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#define _CRT_SECURE_NO_WARNINGS 1
/* The #define doesn't seem to work, but the #pragma does.. */
@ -95,6 +97,7 @@ int windows_kevent_wait(struct kqueue *, int, const struct timespec *);
int windows_kevent_copyout(struct kqueue *, int, struct kevent *, int);
int windows_filter_init(struct kqueue *, struct filter *);
void windows_filter_free(struct kqueue *, struct filter *);
int windows_get_descriptor_type(struct knote *);
/* Windows does not support this attribute.
DllMain() is the only available constructor function.

View File

@ -89,6 +89,8 @@ get_eof_offset(int fd)
int
evfilt_read_copyout(struct kevent *dst, struct knote *src, void *ptr)
{
unsigned long bufsize;
//struct event_buf * const ev = (struct event_buf *) ptr;
/* TODO: handle regular files
@ -102,8 +104,11 @@ evfilt_read_copyout(struct kevent *dst, struct knote *src, void *ptr)
/* On return, data contains the number of bytes of protocol
data available to read.
*/
/* FIXME: use WSAIoctl and FIONREAD to get the actual value */
dst->data = 1;
if (ioctlsocket(src->kev.ident, FIONREAD, &bufsize) != 0) {
dbg_wsalasterror("ioctlsocket");
return (-1);
}
dst->data = bufsize;
}
return (0);
@ -115,6 +120,9 @@ evfilt_read_knote_create(struct filter *filt, struct knote *kn)
HANDLE evt;
int rv;
if (windows_get_descriptor_type(kn) < 0)
return (-1);
/* Create an auto-reset event object */
evt = CreateEvent(NULL, FALSE, FALSE, NULL);
if (evt == NULL) {
@ -163,9 +171,6 @@ evfilt_read_knote_modify(struct filter *filt, struct knote *kn,
int
evfilt_read_knote_delete(struct filter *filt, struct knote *kn)
{
if (kn->kev.flags & EV_DISABLE)
return (0);
if (kn->data.handle == NULL || kn->kn_event_whandle == NULL)
return (0);