extern struct event_list timequeue;
extern struct event_list addqueue;
+#if 0
extern struct event_list signalqueue;
+#endif
struct win_fd_set {
u_int fd_count;
/* MSDN says this is required to handle SIGFPE */
volatile double SIGFPE_REQ = 0.0f;
+#if 0
static void signal_handler(int sig);
void signal_process(void);
int signal_recalc(void);
+#endif
struct win32op {
int fd_setsz;
winop->readset_out->fd_count = winop->writeset_out->fd_count
= winop->exset_out->fd_count = 0;
+ evsignal_init(_base);
+
return (winop);
err:
XFREE(winop->readset_in);
int
win32_recalc(struct event_base *base, void *arg, int max)
{
- return (signal_recalc());
+#if 0
+ return (evsignal_recalc());
+#endif
+ return (0);
}
int
int i;
if (ev->ev_events & EV_SIGNAL) {
- if (ev->ev_events & (EV_READ|EV_WRITE))
- event_errx(1, "%s: EV_SIGNAL incompatible use",
- __func__);
- if((int)signal(EVENT_SIGNAL(ev), signal_handler) == -1)
- return (-1);
-
- return (0);
+ return (evsignal_add(ev));
}
if (!(ev->ev_events & (EV_READ|EV_WRITE)))
return (0);
int i, found;
if (ev->ev_events & EV_SIGNAL)
- return ((int)signal(EVENT_SIGNAL(ev), SIG_IGN));
+ return (evsignal_del(ev));
found = -1;
for (i=0;i<win32op->n_events;++i) {
if (!fd_count) {
/* Windows doesn't like you to call select() with no sockets */
Sleep(timeval_to_ms(tv));
- signal_process();
+ evsignal_process(base);
return (0);
}
event_debug(("%s: select returned %d", __func__, res));
if(res <= 0) {
- signal_process();
+ evsignal_process(base);
return res;
+ } else if (base->sig.evsignal_caught) {
+ evsignal_process(base);
}
for (i=0;i<win32op->n_events;++i) {
event_active(ev,got,1);
}
+#if 0
if (signal_recalc() == -1)
return (-1);
+#endif
return (0);
}
{
struct win32op *win32op = arg;
+ evsignal_dealloc(_base);
if (win32op->readset_in)
free(win32op->readset_in);
if (win32op->writeset_in)
free(win32op);
}
+#if 0
static void
signal_handler(int sig)
{
memset(evsigcaught, 0, sizeof(evsigcaught));
signal_caught = 0;
}
+#endif
+
#include "config.h"
#endif
+#ifdef WIN32
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <winsock2.h>
+#undef WIN32_LEAN_AND_MEAN
+#endif
#include <sys/types.h>
#include <sys/tree.h>
#ifdef HAVE_SYS_TIME_H
#include <sys/_time.h>
#endif
#include <sys/queue.h>
+#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
+#endif
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include "event.h"
#include "event-internal.h"
#include "evsignal.h"
+#include "evutil.h"
#include "log.h"
struct event_base *evsignal_base = NULL;
struct event *ev = arg;
ssize_t n;
- n = read(fd, signals, sizeof(signals));
+ n = recv(fd, signals, sizeof(signals), 0);
if (n == -1)
event_err(1, "%s: read", __func__);
event_add(ev, NULL);
* pair to wake up our event loop. The event loop then scans for
* signals that got delivered.
*/
- if (socketpair(AF_UNIX, SOCK_STREAM, 0, base->sig.ev_signal_pair) == -1)
+ if (evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, base->sig.ev_signal_pair) == -1)
event_err(1, "%s: socketpair", __func__);
FD_CLOSEONEXEC(base->sig.ev_signal_pair[0]);
base->sig.evsignal_caught = 0;
memset(&base->sig.evsigcaught, 0, sizeof(sig_atomic_t)*NSIG);
- fcntl(base->sig.ev_signal_pair[0], F_SETFL, O_NONBLOCK);
+ evutil_make_socket_nonblocking(base->sig.ev_signal_pair[0]);
event_set(&base->sig.ev_signal, base->sig.ev_signal_pair[1], EV_READ,
evsignal_cb, &base->sig.ev_signal);
evsignal_add(struct event *ev)
{
int evsignal;
+#ifdef HAVE_SIGACTION
struct sigaction sa;
+#endif
struct event_base *base = ev->ev_base;
if (ev->ev_events & (EV_READ|EV_WRITE))
event_errx(1, "%s: EV_SIGNAL incompatible use", __func__);
evsignal = EVENT_SIGNAL(ev);
+#ifdef HAVE_SIGACTION
memset(&sa, 0, sizeof(sa));
sa.sa_handler = evsignal_handler;
sigfillset(&sa.sa_mask);
if (sigaction(evsignal, &sa, NULL) == -1)
return (-1);
+#else
+ evsignal_base = base;
+ if (signal(evsignal, evsignal_handler) == SIG_ERR)
+ return (-1);
+#endif
if (!base->sig.ev_signal_added) {
base->sig.ev_signal_added = 1;
int
evsignal_del(struct event *ev)
{
+#ifdef HAVE_SIGACTION
return (sigaction(EVENT_SIGNAL(ev),(struct sigaction *)SIG_DFL, NULL));
+#else
+ return (signal(EVENT_SIGNAL(ev),SIG_DFL))==SIG_ERR ? -1 : 0;
+#endif
}
static void
evsignal_base->sig.evsigcaught[sig]++;
evsignal_base->sig.evsignal_caught = 1;
+#ifndef HAVE_SIGACTION
+ signal(sig, evsignal_handler);
+#endif
+
/* Wake up our notification mechanism */
- write(evsignal_base->sig.ev_signal_pair[0], "a", 1);
+ send(evsignal_base->sig.ev_signal_pair[0], "a", 1, 0);
errno = save_errno;
}
}
assert(TAILQ_EMPTY(&base->sig.signalqueue));
- close(base->sig.ev_signal_pair[0]);
+ EVUTIL_CLOSESOCKET(base->sig.ev_signal_pair[0]);
base->sig.ev_signal_pair[0] = -1;
- close(base->sig.ev_signal_pair[1]);
+ EVUTIL_CLOSESOCKET(base->sig.ev_signal_pair[1]);
base->sig.ev_signal_pair[1] = -1;
}