summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiels Provos <provos@gmail.com>2006-08-10 05:08:41 +0000
committerNiels Provos <provos@gmail.com>2006-08-10 05:08:41 +0000
commitb4de7e8fa64d3c50958109be9f98accf1abb8aad (patch)
tree44f90f864a25f0f88650972fb048b29fca534dba
parente1759c7bbde90093709b70020fadc8a9f90416d5 (diff)
downloadlibevent-b4de7e8fa64d3c50958109be9f98accf1abb8aad.tar.gz
integrate bug fix patches; help form nick mathewson
svn:r221
-rw-r--r--Makefile.am7
-rw-r--r--README1
-rw-r--r--WIN32-Code/win32.c2
-rw-r--r--WIN32-Prj/libevent.dsp2
-rw-r--r--buffer.c83
-rw-r--r--configure.in2
-rw-r--r--devpoll.c2
-rw-r--r--epoll.c10
-rw-r--r--event.c11
-rw-r--r--event.h7
-rw-r--r--kqueue.c4
-rw-r--r--signal.c14
12 files changed, 90 insertions, 55 deletions
diff --git a/Makefile.am b/Makefile.am
index e08bc03f..3dbee885 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -13,11 +13,10 @@ EXTRA_DIST = acconfig.h event.h event-internal.h log.h evsignal.h event.3 \
compat/sys/queue.h compat/sys/tree.h compat/sys/_time.h \
WIN32-Code WIN32-Code/config.h WIN32-Code/misc.c \
WIN32-Code/win32.c WIN32-Code/misc.h \
- WIN32-Prj WIN32-Prj/event_test WIN32-Prj/event_test/event_test.dsp \
+ WIN32-Prj/event_test/event_test.dsp \
WIN32-Prj/event_test/test.txt WIN32-Prj/libevent.dsp \
- WIN32-Prj/libevent.dsw WIN32-Prj/signal_test \
- WIN32-Prj/signal_test/signal_test.dsp WIN32-Prj/time_test \
- WIN32-Prj/time_test/time_test.dsp
+ WIN32-Prj/libevent.dsw WIN32-Prj/signal_test/signal_test.dsp \
+ WIN32-Prj/time_test WIN32-Prj/time_test/time_test.dsp
lib_LTLIBRARIES = libevent.la
diff --git a/README b/README
index b978fe98..b8f69cde 100644
--- a/README
+++ b/README
@@ -24,5 +24,6 @@ fixing bugs:
Mike Davis
William Ahern
Alexander von Gernler
+ Artur Grabowski
If I have forgotten your name, please contact me.
diff --git a/WIN32-Code/win32.c b/WIN32-Code/win32.c
index f4cc2d8a..90a663a5 100644
--- a/WIN32-Code/win32.c
+++ b/WIN32-Code/win32.c
@@ -135,6 +135,8 @@ do_fd_set(struct win32op *op, SOCKET s, int read)
if (set->fd_count == op->fd_setsz) {
if (realloc_fd_sets(op, op->fd_setsz*2))
return (-1);
+ /* set pointer will have changed and needs reiniting! */
+ set = read ? op->readset_in : op->writeset_in;
}
set->fd_array[set->fd_count] = s;
return (set->fd_count++);
diff --git a/WIN32-Prj/libevent.dsp b/WIN32-Prj/libevent.dsp
index 2c7d87c3..61e9bc84 100644
--- a/WIN32-Prj/libevent.dsp
+++ b/WIN32-Prj/libevent.dsp
@@ -85,7 +85,7 @@ LIB32=link.exe -lib
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
-SOURCE=..\err.c
+SOURCE=..\log.c
# End Source File
# Begin Source File
diff --git a/buffer.c b/buffer.c
index ff59ed78..e641e91f 100644
--- a/buffer.c
+++ b/buffer.c
@@ -117,45 +117,55 @@ evbuffer_add_buffer(struct evbuffer *outbuf, struct evbuffer *inbuf)
}
res = evbuffer_add(outbuf, inbuf->buffer, inbuf->off);
- if (res == 0)
+ if (res == 0) {
+ /* We drain the input buffer on success */
evbuffer_drain(inbuf, inbuf->off);
+ }
return (res);
}
int
-evbuffer_add_printf(struct evbuffer *buf, char *fmt, ...)
+evbuffer_add_vprintf(struct evbuffer *buf, const char *fmt, va_list ap)
{
- int res = -1;
- char *msg;
-#ifndef HAVE_VASPRINTF
- static char buffer[4096];
-#endif
- va_list ap;
+ char *buffer;
+ size_t space;
+ size_t oldoff = buf->off;
+ int sz;
- va_start(ap, fmt);
+ for (;;) {
+ buffer = buf->buffer + buf->off;
+ space = buf->totallen - buf->misalign - buf->off;
-#ifdef HAVE_VASPRINTF
- if (vasprintf(&msg, fmt, ap) == -1)
- goto end;
+#ifdef WIN32
+ sz = vsnprintf(buffer, space - 1, fmt, ap);
+ buffer[space - 1] = '\0';
#else
-# ifdef WIN32
- _vsnprintf(buffer, sizeof(buffer) - 1, fmt, ap);
- buffer[sizeof(buffer)-1] = '\0';
-# else /* ! WIN32 */
- vsnprintf(buffer, sizeof(buffer), fmt, ap);
-# endif
- msg = buffer;
+ sz = vsnprintf(buffer, space, fmt, ap);
#endif
-
- res = strlen(msg);
- if (evbuffer_add(buf, msg, res) == -1)
- res = -1;
-#ifdef HAVE_VASPRINTF
- free(msg);
+ if (sz == -1)
+ return (-1);
+ if (sz < space) {
+ buf->off += sz;
+ if (buf->cb != NULL)
+ (*buf->cb)(buf, oldoff, buf->off, buf->cbarg);
+ return (sz);
+ }
+ if (evbuffer_expand(buf, sz + 1) == -1)
+ return (-1);
-end:
-#endif
+ }
+ /* NOTREACHED */
+}
+
+int
+evbuffer_add_printf(struct evbuffer *buf, const char *fmt, ...)
+{
+ int res = -1;
+ va_list ap;
+
+ va_start(ap, fmt);
+ res = evbuffer_add_vprintf(buf, fmt, ap);
va_end(ap);
return (res);
@@ -193,7 +203,7 @@ evbuffer_readline(struct evbuffer *buffer)
if (data[i] == '\r' || data[i] == '\n')
break;
}
-
+
if (i == len)
return (NULL);
@@ -332,8 +342,21 @@ evbuffer_read(struct evbuffer *buf, int fd, int howmuch)
#endif
#ifdef FIONREAD
- if (ioctl(fd, FIONREAD, &n) == -1 || n == 0)
+ if (ioctl(fd, FIONREAD, &n) == -1 || n == 0) {
n = EVBUFFER_MAX_READ;
+ } else if (n > EVBUFFER_MAX_READ && n > howmuch) {
+ /*
+ * It's possible that a lot of data is available for
+ * reading. We do not want to exhaust resources
+ * before the reader has a chance to do something
+ * about it. If the reader does not tell us how much
+ * data we should read, we artifically limit it.
+ */
+ if (n > buf->totallen << 2)
+ n = buf->totallen << 2;
+ if (n < EVBUFFER_MAX_READ)
+ n = EVBUFFER_MAX_READ;
+ }
#endif
if (howmuch < 0 || howmuch > n)
howmuch = n;
@@ -397,7 +420,7 @@ evbuffer_write(struct evbuffer *buffer, int fd)
}
u_char *
-evbuffer_find(struct evbuffer *buffer, u_char *what, size_t len)
+evbuffer_find(struct evbuffer *buffer, const u_char *what, size_t len)
{
size_t remain = buffer->off;
u_char *search = buffer->buffer;
diff --git a/configure.in b/configure.in
index b75d2d66..a27959f9 100644
--- a/configure.in
+++ b/configure.in
@@ -2,7 +2,7 @@ dnl configure.in for libevent
dnl Dug Song <dugsong@monkey.org>
AC_INIT(event.c)
-AM_INIT_AUTOMAKE(libevent,1.1a)
+AM_INIT_AUTOMAKE(libevent,1.1b)
AM_CONFIG_HEADER(config.h)
AM_MAINTAINER_MODE
diff --git a/devpoll.c b/devpoll.c
index 68def058..ab050d44 100644
--- a/devpoll.c
+++ b/devpoll.c
@@ -140,7 +140,7 @@ devpoll_init(void)
if (getrlimit(RLIMIT_NOFILE, &rl) == 0 &&
rl.rlim_cur != RLIM_INFINITY)
- nfiles = rl.rlim_cur;
+ nfiles = rl.rlim_cur - 1;
/* Initialize the kernel queue */
if ((dpfd = open("/dev/poll", O_RDWR)) == -1) {
diff --git a/epoll.c b/epoll.c
index 9f1066d8..bdab078b 100644
--- a/epoll.c
+++ b/epoll.c
@@ -109,8 +109,14 @@ epoll_init(void)
return (NULL);
if (getrlimit(RLIMIT_NOFILE, &rl) == 0 &&
- rl.rlim_cur != RLIM_INFINITY)
- nfiles = rl.rlim_cur;
+ rl.rlim_cur != RLIM_INFINITY) {
+ /*
+ * Solaris is somewhat retarded - it's important to drop
+ * backwards compatibility when making changes. So, don't
+ * dare to put rl.rlim_cur here.
+ */
+ nfiles = rl.rlim_cur - 1;
+ }
/* Initalize the kernel queue */
diff --git a/event.c b/event.c
index 2a2150ac..0d6de870 100644
--- a/event.c
+++ b/event.c
@@ -313,12 +313,12 @@ event_base_loop(struct event_base *base, int flags)
struct timeval tv;
int res, done;
- /* Calculate the initial events that we are waiting for */
- if (evsel->recalc(base, evbase, 0) == -1)
- return (-1);
-
done = 0;
while (!done) {
+ /* Calculate the initial events that we are waiting for */
+ if (evsel->recalc(base, evbase, 0) == -1)
+ return (-1);
+
/* Terminate the loop if we have been asked to */
if (base->event_gotterm) {
base->event_gotterm = 0;
@@ -372,9 +372,6 @@ event_base_loop(struct event_base *base, int flags)
done = 1;
} else if (flags & EVLOOP_NONBLOCK)
done = 1;
-
- if (evsel->recalc(base, evbase, 0) == -1)
- return (-1);
}
event_debug(("%s: asked to terminate loop.", __func__));
diff --git a/event.h b/event.h
index 857dd376..174ac727 100644
--- a/event.h
+++ b/event.h
@@ -31,6 +31,8 @@
extern "C" {
#endif
+#include <stdarg.h>
+
#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
@@ -263,11 +265,12 @@ int evbuffer_add(struct evbuffer *, void *, size_t);
int evbuffer_remove(struct evbuffer *, void *, size_t);
char *evbuffer_readline(struct evbuffer *);
int evbuffer_add_buffer(struct evbuffer *, struct evbuffer *);
-int evbuffer_add_printf(struct evbuffer *, char *fmt, ...);
+int evbuffer_add_printf(struct evbuffer *, const char *fmt, ...);
+int evbuffer_add_vprintf(struct evbuffer *, const char *fmt, va_list ap);
void evbuffer_drain(struct evbuffer *, size_t);
int evbuffer_write(struct evbuffer *, int);
int evbuffer_read(struct evbuffer *, int, int);
-u_char *evbuffer_find(struct evbuffer *, u_char *, size_t);
+u_char *evbuffer_find(struct evbuffer *, const u_char *, size_t);
void evbuffer_setcb(struct evbuffer *, void (*)(struct evbuffer *, size_t, size_t, void *), void *);
#ifdef __cplusplus
diff --git a/kqueue.c b/kqueue.c
index 3bc6c2db..d760440c 100644
--- a/kqueue.c
+++ b/kqueue.c
@@ -266,10 +266,8 @@ kq_dispatch(struct event_base *base, void *arg, struct timeval *tv)
if (!which)
continue;
- if (!(ev->ev_events & EV_PERSIST)) {
- ev->ev_flags &= ~EVLIST_X_KQINKERNEL;
+ if (!(ev->ev_events & EV_PERSIST))
event_del(ev);
- }
event_active(ev, which,
ev->ev_events & EV_SIGNAL ? events[i].data : 1);
diff --git a/signal.c b/signal.c
index 19a85f14..978b7ba2 100644
--- a/signal.c
+++ b/signal.c
@@ -52,7 +52,7 @@
extern struct event_list signalqueue;
-static short evsigcaught[NSIG];
+static sig_atomic_t evsigcaught[NSIG];
static int needrecalc;
volatile sig_atomic_t evsignal_caught = 0;
@@ -61,11 +61,12 @@ static int ev_signal_pair[2];
static int ev_signal_added;
/* Callback for when the signal handler write a byte to our signaling socket */
-static void evsignal_cb(int fd, short what, void *arg)
+static void
+evsignal_cb(int fd, short what, void *arg)
{
static char signals[100];
struct event *ev = arg;
- int n;
+ ssize_t n;
n = read(fd, signals, sizeof(signals));
if (n == -1)
@@ -98,6 +99,8 @@ evsignal_init(sigset_t *evsigmask)
FD_CLOSEONEXEC(ev_signal_pair[0]);
FD_CLOSEONEXEC(ev_signal_pair[1]);
+ fcntl(ev_signal_pair[0], F_SETFL, O_NONBLOCK);
+
event_set(&ev_signal, ev_signal_pair[1], EV_READ,
evsignal_cb, &ev_signal);
ev_signal.ev_flags |= EVLIST_INTERNAL;
@@ -135,11 +138,14 @@ evsignal_del(sigset_t *evsigmask, struct event *ev)
static void
evsignal_handler(int sig)
{
+ int save_errno = errno;
+
evsigcaught[sig]++;
evsignal_caught = 1;
/* Wake up our notification mechanism */
write(ev_signal_pair[0], "a", 1);
+ errno = save_errno;
}
int
@@ -187,7 +193,7 @@ void
evsignal_process(void)
{
struct event *ev;
- short ncalls;
+ sig_atomic_t ncalls;
TAILQ_FOREACH(ev, &signalqueue, ev_signal_next) {
ncalls = evsigcaught[EVENT_SIGNAL(ev)];