Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/windows/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,12 @@ typedef CRITICAL_SECTION pthread_rwlock_t;
#define pthread_rwlock_unlock LeaveCriticalSection
#define pthread_rwlock_init(x,y) InitializeCriticalSection((x))

/* Emulate the POSIX symbolic names for the 'how' argument to shutdown(2) */
#define SHUT_RD SD_RECEIVE
#define SHUT_WR SD_SEND
#define SHUT_RDWR SD_BOTH

/* Emulate the POSIX pipe(2) interface */
#define pipe(x) _pipe(x, 512, 0)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd wrap a lot of these in ifdef _MSC_VER

MinGW supports a lot of this, including pthread.


#endif /* ! _KQUEUE_WINDOWS_PLATFORM_H */
1 change: 0 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ set(LIBKQUEUE_TEST_SOURCES
kqueue.c
libkqueue.c
main.c
proc.c
read.c
test.c
timer.c
Expand Down
6 changes: 4 additions & 2 deletions test/libkqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ static void
test_libkqueue_version(struct test_context *ctx)
{
struct kevent kev, receipt;
struct timespec ts = {0, 0};

EV_SET(&kev, 0, EVFILT_LIBKQUEUE, EV_ADD, NOTE_VERSION, 0, NULL);
if (kevent(ctx->kqfd, &kev, 1, &receipt, 1, &(struct timespec){}) != 1) {
if (kevent(ctx->kqfd, &kev, 1, &receipt, 1, &ts) != 1) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Windows still doesn't support C11?!

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it still doesn't support compound literals. I even tried enabling the latest conforming preprocessor:

https://devblogs.microsoft.com/cppblog/announcing-full-support-for-a-c-c-conformant-preprocessor-in-msvc/

printf("Unable to add the following kevent:\n%s\n",
kevent_to_str(&kev));
die("kevent");
Expand All @@ -38,9 +39,10 @@ static void
test_libkqueue_version_str(struct test_context *ctx)
{
struct kevent kev, receipt;
struct timespec ts = { 0, 0 };

EV_SET(&kev, 0, EVFILT_LIBKQUEUE, EV_ADD, NOTE_VERSION_STR, 0, NULL);
if (kevent(ctx->kqfd, &kev, 1, &receipt, 1, &(struct timespec){}) != 1) {
if (kevent(ctx->kqfd, &kev, 1, &receipt, 1, &ts) != 1) {
printf("Unable to add the following kevent:\n%s\n",
kevent_to_str(&kev));
die("kevent");
Expand Down
2 changes: 2 additions & 0 deletions test/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,12 @@ main(int argc, char **argv)
.ut_func = test_evfilt_signal,
.ut_end = INT_MAX },
#endif
#if !defined(_WIN32)
{ .ut_name = "proc",
.ut_enabled = 1,
.ut_func = test_evfilt_proc,
.ut_end = INT_MAX },
#endif
{ .ut_name = "timer",
.ut_enabled = 1,
.ut_func = test_evfilt_timer,
Expand Down
6 changes: 6 additions & 0 deletions test/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,11 @@ test_kevent_regular_file(struct test_context *ctx)
void
test_transition_from_write_to_read(struct test_context *ctx)
{
#if defined(_WIN32)
// socketpair() is not available on Windows.
return;
#else

struct kevent kev, ret[1];
int kqfd;
int sd[2];
Expand All @@ -613,6 +618,7 @@ test_transition_from_write_to_read(struct test_context *ctx)
close(sd[0]);
close(sd[1]);
close(kqfd);
#endif
}

void
Expand Down
12 changes: 9 additions & 3 deletions test/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@

#include "common.h"

#if defined(_WIN32)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MinGW supports usleep.

#define SLEEP_MS(ms) Sleep(ms)
#else
#define SLEEP_MS(microseconds) usleep(microseconds * 1000)
#endif

void
test_kevent_timer_add(struct test_context *ctx)
{
Expand Down Expand Up @@ -204,7 +210,7 @@ test_kevent_timer_dispatch(struct test_context *ctx)
kevent_cmp(&kev, ret);

/* Confirm that the knote is disabled due to EV_DISPATCH */
usleep(500000); /* 500 ms */
SLEEP_MS(500);
test_no_kevents(ctx->kqfd);

#if WITH_NATIVE_KQUEUE_BUGS || !defined(__FreeBSD__)
Expand All @@ -223,7 +229,7 @@ test_kevent_timer_dispatch(struct test_context *ctx)
test_no_kevents(ctx->kqfd);

/* Get the next event */
usleep(1100000); /* 1100 ms */
SLEEP_MS(1100);
kev.flags = EV_ADD | EV_CLEAR | EV_DISPATCH;
kev.data = 5;
kevent_get(ret, NUM_ELEMENTS(ret), ctx->kqfd, 1);
Expand All @@ -232,7 +238,7 @@ test_kevent_timer_dispatch(struct test_context *ctx)

/* Remove the knote and ensure the event no longer fires */
kevent_add(ctx->kqfd, &kev, 4, EVFILT_TIMER, EV_DELETE, 0, 0, NULL);
usleep(500000); /* 500 ms */
SLEEP_MS(500);
test_no_kevents(ctx->kqfd);
}
#endif /* EV_DISPATCH */
Expand Down