o Fix connection keep-alive behavior for HTTP/1.0
o Fix use of freed memory in event_reinit; pointed out by Peter Postma
o constify struct timeval * where possible
-
+ o make event_get_supported_methods obey environment variables
+
Changes in 1.4.0:
o allow \r or \n individually to separate HTTP headers instead of the standard "\r\n"; from Charles Kerr.
o demote most http warnings to debug messages
struct rlimit rl;
struct devpollop *devpollop;
- /* Disable devpoll when this environment variable is set */
- if (getenv("EVENT_NODEVPOLL"))
- return (NULL);
-
if (!(devpollop = mm_calloc(1, sizeof(struct devpollop))))
return (NULL);
struct rlimit rl;
struct epollop *epollop;
- /* Disable epollueue when this environment variable is set */
- if (getenv("EVENT_NOEPOLL"))
- return (NULL);
-
if (getrlimit(RLIMIT_NOFILE, &rl) == 0 &&
rl.rlim_cur != RLIM_INFINITY) {
/*
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
+#include <ctype.h>
#include <errno.h>
#include <signal.h>
#include <string.h>
return (0);
}
+static int
+event_is_method_disabled(const char *name)
+{
+ char environment[64];
+ int i;
+
+ evutil_snprintf(environment, sizeof(environment), "EVENT_NO%s", name);
+ for (i = 8; environment[i] != '\0'; ++i)
+ environment[i] = toupper(environment[i]);
+ return (getenv(environment) != NULL);
+
+}
+
struct event_base *
event_base_new_with_config(struct event_config *cfg)
{
continue;
}
+ /* also obey the environment variables */
+ if (event_is_method_disabled(eventops[i]->name))
+ continue;
+
base->evsel = eventops[i];
base->evbase = base->evsel->init(base);
event_errx(1, "%s: no event mechanism available", __func__);
if (getenv("EVENT_SHOW_METHOD"))
- event_msgx("libevent using: %s\n",
- base->evsel->name);
+ event_msgx("libevent using: %s", base->evsel->name);
/* allocate a single active event queue */
event_base_priority_init(base, 1);
const char **tmp;
int i = 0, k;
- if (methods != NULL)
- return (methods);
-
/* count all methods */
- for (method = &eventops[0]; *method != NULL; ++method)
+ for (method = &eventops[0]; *method != NULL; ++method) {
+ if (event_is_method_disabled((*method)->name))
+ continue;
++i;
+ }
/* allocate one more than we need for the NULL pointer */
tmp = mm_malloc((i + 1) * sizeof(char *));
return (NULL);
/* populate the array with the supported methods */
- for (k = 0; k < i; ++k)
- tmp[k] = eventops[k]->name;
+ for (k = 0, i = 0; eventops[k] != NULL; ++k) {
+ if (event_is_method_disabled(eventops[k]->name))
+ continue;
+ tmp[i++] = eventops[k]->name;
+ }
tmp[i] = NULL;
+ if (methods != NULL)
+ mm_free(methods);
+
methods = tmp;
return (methods);
{
struct evport_data *evpd;
int i;
- /*
- * Disable event ports when this environment variable is set
- */
- if (getenv("EVENT_NOEVPORT"))
- return (NULL);
if (!(evpd = mm_calloc(1, sizeof(struct evport_data))))
return (NULL);
int kq;
struct kqop *kqueueop;
- /* Disable kqueue when this environment variable is set */
- if (getenv("EVENT_NOKQUEUE"))
- return (NULL);
-
if (!(kqueueop = mm_calloc(1, sizeof(struct kqop))))
return (NULL);
{
struct pollop *pollop;
- /* Disable poll when this environment variable is set */
- if (getenv("EVENT_NOPOLL"))
- return (NULL);
-
if (!(pollop = mm_calloc(1, sizeof(struct pollop))))
return (NULL);
{
struct selectop *sop;
- /* Disable select when this environment variable is set */
- if (getenv("EVENT_NOSELECT"))
- return (NULL);
-
if (!(sop = mm_calloc(1, sizeof(struct selectop))))
return (NULL);
if ((pid = fork()) == 0) {
/* in the child */
if (event_reinit(current_base) == -1) {
- fprintf(stderr, "FAILED (reinit)\n");
+ fprintf(stdout, "FAILED (reinit)\n");
exit(1);
}
write(pair[0], TEST1, strlen(TEST1)+1);
if (waitpid(pid, &status, 0) == -1) {
- fprintf(stderr, "FAILED (fork)\n");
+ fprintf(stdout, "FAILED (fork)\n");
exit(1);
}
if (WEXITSTATUS(status) != 76) {
- fprintf(stderr, "FAILED (exit): %d\n", WEXITSTATUS(status));
+ fprintf(stdout, "FAILED (exit): %d\n", WEXITSTATUS(status));
exit(1);
}
gettimeofday(&tv_end, NULL);
evutil_timersub(&tv_end, &tv_start, &tv_end);
- fprintf(stderr, "(%.1f us/add) ",
+ fprintf(stdout, "(%.1f us/add) ",
(float)tv_end.tv_sec/(float)i * 1000000.0 +
tv_end.tv_usec / (float)i);
const char *backend;
int n_methods = 0;
- fprintf(stderr, "Testing supported methods: ");
+ fprintf(stdout, "Testing supported methods: ");
if (methods == NULL) {
- fprintf(stderr, "FAILED\n");
+ fprintf(stdout, "FAILED\n");
exit(1);
}
backend = methods[0];
while (*methods != NULL) {
- fprintf(stderr, "%s ", *methods);
+ fprintf(stdout, "%s ", *methods);
++methods;
++n_methods;
}
base = event_base_new_with_config(cfg);
if (base == NULL) {
- fprintf(stderr, "FAILED\n");
+ fprintf(stdout, "FAILED\n");
exit(1);
}
if (strcmp(backend, event_base_get_method(base)) == 0) {
- fprintf(stderr, "FAILED\n");
+ fprintf(stdout, "FAILED\n");
exit(1);
}
event_base_free(base);
event_config_free(cfg);
done:
- fprintf(stderr, "OK\n");
+ fprintf(stdout, "OK\n");
}