Rollback to r371 to eliminate kqtest failure on Solaris

git-svn-id: svn://svn.code.sf.net/p/libkqueue/code/trunk@379 fb4e3144-bc1c-4b72-a658-5bcd248dd7f7
This commit is contained in:
mheily 2011-01-15 17:43:12 +00:00
parent ad93cfbc8b
commit ef63a7a6ff
15 changed files with 49 additions and 242 deletions

View File

@ -1,9 +1,6 @@
HEAD
------------------------------------------------------------------------
* NOTE: r368 is the last version to work properly on Solaris.
The HEAD fails the unit tests
* Add a counter that increments on each each kevent() call. When printing
debug information within kevent(), display the value of the counter.
This will be helpful when debugging a multithreaded program that may have

View File

@ -152,4 +152,4 @@ diff:
# Used for testing on a Solaris guest VM
#
solaris-test:
make dist && scp -P 2222 libkqueue-1.0a.tar.gz localhost:/tmp && ssh -p 2222 localhost ". .profile ; cd /tmp ; rm -rf libkqueue-$(VERSION) ; gtar zxvf libkqueue-$(VERSION).tar.gz && cd libkqueue-$(VERSION) && ./configure && make && KQUEUE_DEBUG=yes make check"
make dist && scp -P 2222 libkqueue-1.0a.tar.gz localhost:/tmp && ssh -p 2222 localhost ". .profile ; cd /tmp ; rm -rf libkqueue-$(VERSION) ; gtar zxvf libkqueue-$(VERSION).tar.gz && cd libkqueue-$(VERSION) && ./configure && make && make check"

View File

@ -50,7 +50,7 @@ pre_configure_hook() {
post_configure_hook() {
finalize target "$target"
kqueue="src/posix/kqueue.c"
kqueue=""
kevent="src/posix/kevent.c"
evfilt_signal="src/posix/signal.c"
evfilt_proc="src/$target/proc.c"
@ -75,7 +75,7 @@ post_configure_hook() {
if [ $target = "solaris" ] ; then
cflags="$cflags -D__EXTENSIONS__"
kqueue="$kqueue src/solaris/kqueue.c"
kqueue="src/solaris/kqueue.c"
kevent="src/solaris/kevent.c"
evfilt_timer="src/solaris/timer.c"
evfilt_user="src/solaris/user.c"

View File

@ -40,11 +40,6 @@
#define LIBKQUEUE 1
#endif
#ifndef _WIN32
#define __declspec(x) /* */
#define dllexport 0
#endif
struct timespec;
#define EVFILT_READ (-1)
@ -175,10 +170,7 @@ struct kevent {
extern "C" {
#endif
__declspec(dllexport)
int kqueue(void);
__declspec(dllexport)
int kevent(int kq, const struct kevent *changelist, int nchanges,
struct kevent *eventlist, int nevents,
const struct timespec *timeout);

View File

@ -123,23 +123,17 @@ filter_unregister_all(struct kqueue *kq)
int
filter_socketpair(struct filter *filt)
{
#ifndef _WIN32
int sockfd[2];
#ifdef _WIN32
if (_pipe(sockfd, 512, _O_BINARY) == -1) {
dbg_puts("_pipe failed");
return (-1);
}
/* FIXME: want nonblocking behavior for writer */
filt->kf_wfd = sockfd[0];
filt->kf_pfd = sockfd[1];
#else
if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockfd) < 0)
return (-1);
fcntl(sockfd[0], F_SETFL, O_NONBLOCK);
filt->kf_wfd = sockfd[0];
filt->kf_pfd = sockfd[1];
#else
#warning FIXME function has no effect
#endif
return (0);
}

View File

@ -227,11 +227,10 @@ err_path:
return (nret);
}
VISIBLE_DECL(int,
int VISIBLE
kevent(int kqfd, const struct kevent *changelist, int nchanges,
struct kevent *eventlist, int nevents,
const struct timespec *timeout)
)
{
static unsigned int _kevent_counter = 0;
struct kqueue *kq;

View File

@ -156,7 +156,7 @@ knote_get_socket_type(struct knote *kn)
return (0);
break;
default:
dbg_perror("getsockopt(3)");
dbg_printf("getsockopt(3) failed: %s", strerror(errno));
return (-1);
}
} else {

View File

@ -24,7 +24,10 @@
#include "private.h"
#ifndef NDEBUG
int KQUEUE_DEBUG = 0;
#endif
static RB_HEAD(kqt, kqueue) kqtree = RB_INITIALIZER(&kqtree);
static pthread_rwlock_t kqtree_mtx;
@ -145,9 +148,14 @@ kqueue_get(int kq)
return (ent);
}
VISIBLE_DECL(int, kqueue(void))
int VISIBLE
kqueue(void)
{
#ifdef _WIN32
static int kqueue_id = 0;
#endif
struct kqueue *kq;
int tmp;
kq = calloc(1, sizeof(*kq));
if (kq == NULL)
@ -164,8 +172,21 @@ VISIBLE_DECL(int, kqueue(void))
KQUEUE_DEBUG = (getenv("KQUEUE_DEBUG") == NULL) ? 0 : 1;
#endif
#ifdef _WIN32
pthread_rwlock_wrlock(&kqtree_mtx);
kqueue_id++;
pthread_rwlock_unlock(&kqtree_mtx);
kq->kq_sockfd[0] = kqueue_id;
kq->kq_sockfd[1] = kqueue_id;
#else
if (socketpair(AF_UNIX, SOCK_STREAM, 0, kq->kq_sockfd) < 0)
goto errout_unlocked;
#endif
#ifdef kqueue_init_hook
if (kqueue_init_hook(kq) < 0)
goto errout_unlocked;
#endif
pthread_rwlock_wrlock(&kqtree_mtx);
if (kqueue_gc() < 0)
@ -183,7 +204,18 @@ errout:
pthread_rwlock_unlock(&kqtree_mtx);
errout_unlocked:
kqueue_free_hook(kq);
if (kq->kq_sockfd[0] != kq->kq_sockfd[1]) {
tmp = errno;
#ifndef _WIN32
(void)close(kq->kq_sockfd[0]);
(void)close(kq->kq_sockfd[1]);
#endif
errno = tmp;
}
#if defined(__sun__)
if (kq->kq_port > 0)
close(kq->kq_port);
#endif
free(kq);
return (-1);
}

View File

@ -43,9 +43,10 @@ struct evfilt_data;
/* Maximum events returnable in a single kevent() call */
#define MAX_KEVENT 512
#ifndef NDEBUG
extern int KQUEUE_DEBUG;
#ifndef NDEBUG
#define dbg_puts(str) do { \
if (KQUEUE_DEBUG) \

View File

@ -1,47 +0,0 @@
/*
* Copyright (c) 2011 Mark Heily <mark@heily.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <string.h>
#include "private.h"
int
posix_kqueue_init(struct kqueue *kq)
{
if (socketpair(AF_UNIX, SOCK_STREAM, 0, kq->kq_sockfd) < 0) {
dbg_perror("socketpair");
kq->kq_sockfd[0] = -1;
kq->kq_sockfd[1] = -1;
return (-1);
}
return (0);
}
void
posix_kqueue_free(struct kqueue *kq)
{
if (kq->kq_sockfd[0] != -1)
(void) close(kq->kq_sockfd[0]);
if (kq->kq_sockfd[1] != -1)
(void) close(kq->kq_sockfd[1]);
}

View File

@ -17,14 +17,7 @@
#ifndef _KQUEUE_POSIX_PLATFORM_H
#define _KQUEUE_POSIX_PLATFORM_H
/*
* Hooks and prototypes
*/
#define kqueue_free_hook posix_kqueue_free
void posix_kqueue_free(struct kqueue *);
#define kqueue_init_hook posix_kqueue_init
int posix_kqueue_init(struct kqueue *);
#include "../../include/sys/event.h"
/*
* GCC-compatible atomic integer operations
@ -33,7 +26,7 @@ int posix_kqueue_init(struct kqueue *);
#define atomic_dec(p) __sync_sub_and_fetch((p), 1)
#define CONSTRUCTOR int __attribute__ ((constructor))
#define VISIBLE
#define VISIBLE __attribute__((visibility("default")))
#define HIDDEN __attribute__((visibility("hidden")))
#include <signal.h>
@ -44,9 +37,4 @@ int posix_kqueue_init(struct kqueue *);
#include <sys/socket.h>
#include <unistd.h>
#define VISIBLE_DECL(t,x) t __attribute__((visibility("default"))) x
#include "../../include/sys/event.h"
#endif /* ! _KQUEUE_POSIX_PLATFORM_H */

View File

@ -22,13 +22,9 @@
#include "sys/event.h"
#include "private.h"
extern int posix_kqueue_init(struct kqueue *kq);
extern void posix_kqueue_free(struct kqueue *kq);
void
solaris_kqueue_free(struct kqueue *kq)
{
posix_kqueue_free(kq);
if (kq->kq_port > 0)
close(kq->kq_port);
}
@ -36,13 +32,10 @@ solaris_kqueue_free(struct kqueue *kq)
int
solaris_kqueue_init(struct kqueue *kq)
{
if (posix_kqueue_init(kq) < 0)
return (-1);
if ((kq->kq_port = port_create()) < 0) {
dbg_perror("port_create(2)");
return (-1);
}
dbg_printf("created event port: fd=%d", kq->kq_port);
TAILQ_INIT(&kq->kq_events);
return (0);
}

View File

@ -41,11 +41,9 @@
/*
* Hooks and prototypes
*/
#undef kqueue_free_hook
#define kqueue_free_hook solaris_kqueue_free
void solaris_kqueue_free(struct kqueue *);
#undef kqueue_init_hook
#define kqueue_init_hook solaris_kqueue_init
int solaris_kqueue_init(struct kqueue *);

View File

@ -1,121 +0,0 @@
/*
* Copyright (c) 2011 Mark Heily <mark@heily.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "../common/private.h"
/* FIXME: remove these as filters are implemented */
const struct filter evfilt_proc = EVFILT_NOTIMPL;
const struct filter evfilt_vnode = EVFILT_NOTIMPL;
const struct filter evfilt_signal = EVFILT_NOTIMPL;
const struct filter evfilt_write = EVFILT_NOTIMPL;
const struct filter evfilt_read = EVFILT_NOTIMPL;
const struct filter evfilt_timer = EVFILT_NOTIMPL;
const struct filter evfilt_user = EVFILT_NOTIMPL;
BOOL WINAPI DllMain(
HINSTANCE self,
DWORD reason,
LPVOID unused)
{
switch (reason) {
case DLL_PROCESS_ATTACH:
/* XXX-FIXME: initialize kqtree mutex */
if (WSAStartup(MAKEWORD(2,2), NULL) != 0)
return (FALSE);
/* TODO: bettererror handling */
break;
case DLL_PROCESS_DETACH:
WSACleanup();
break;
}
return (TRUE);
}
void
windows_kqueue_free(struct kqueue *kq)
{
/*XXX-FIXME close the _pipe() */
}
int
windows_kqueue_init(struct kqueue *kq)
{
if (_pipe(kq->kq_sockfd, 512, _O_BINARY) == -1) {
dbg_puts("_pipe failed");
return (-1);
}
return (0);
}
int
kevent_wait(
struct kqueue *kq,
const struct timespec *timeout)
{
return (0);
#if TODO
int n;
dbg_puts("waiting for events");
kq->kq_rfds = kq->kq_fds;
n = pselect(kq->kq_nfds, &kq->kq_rfds, NULL , NULL, timeout, NULL);
if (n < 0) {
if (errno == EINTR) {
dbg_puts("signal caught");
return (-1);
}
dbg_perror("pselect(2)");
return (-1);
}
return (n);
#endif
}
int
kevent_copyout(struct kqueue *kq, int nready,
struct kevent *eventlist, int nevents)
{
return (0);
#if TODO
struct filter *filt;
int i, rv, nret;
nret = 0;
for (i = 0; (i < EVFILT_SYSCOUNT && nready > 0 && nevents > 0); i++) {
// dbg_printf("eventlist: n = %d nevents = %d", nready, nevents);
filt = &kq->kq_filt[i];
// dbg_printf("pfd[%d] = %d", i, filt->kf_pfd);
if (FD_ISSET(filt->kf_pfd, &kq->kq_rfds)) {
dbg_printf("pending events for filter %d (%s)", filt->kf_id, filter_name(filt->kf_id));
rv = filt->kf_copyout(filt, eventlist, nevents);
if (rv < 0) {
dbg_puts("kevent_copyout failed");
nret = -1;
break;
}
nret += rv;
eventlist += rv;
nevents -= rv;
nready--;
}
}
return (nret);
#endif
}

View File

@ -17,17 +17,10 @@
#ifndef _KQUEUE_WINDOWS_PLATFORM_H
#define _KQUEUE_WINDOWS_PLATFORM_H
#include <winsock2.h>
#include <ws2tcpip.h>
#include <io.h>
#include <stdio.h>
#include <fcntl.h>
#include <windows.h>
#include <winsock.h>
#pragma comment(lib, "Ws2_32.lib")
/* The #define doesn't seem to work, but the #pragma does.. */
#define _CRT_SECURE_NO_WARNINGS 1
#pragma warning( disable : 4996 )
#include "../../include/kqueue.h"
/*
* Atomic integer operations
@ -73,16 +66,4 @@ typedef CRITICAL_SECTION pthread_rwlock_t;
#define pthread_rwlock_unlock _cs_unlock
#define pthread_rwlock_init(x,y) _cs_init((x))
#define VISIBLE_DECL(t,x) __declspec(dllexport) t x
#include "../../include/sys/event.h"
/*
* Hooks and prototypes
*/
#define kqueue_free_hook windows_kqueue_free
void windows_kqueue_free(struct kqueue *);
#define kqueue_init_hook windows_kqueue_init
int windows_kqueue_init(struct kqueue *);
#endif /* ! _KQUEUE_WINDOWS_PLATFORM_H */