Get bench_http to work on Windows; add a switch to enable IOCP.

This commit is contained in:
Christopher Davis 2010-03-02 14:34:30 -08:00 committed by Christopher Davis
parent bf3bfd0c04
commit 4ac38a5c38

View File

@ -47,11 +47,12 @@
#include <event.h> #include <event.h>
#include <evutil.h> #include <evutil.h>
#include <evhttp.h> #include <evhttp.h>
#include <event2/thread.h>
static void http_basic_cb(struct evhttp_request *req, void *arg); static void http_basic_cb(struct evhttp_request *req, void *arg);
static char *content; static char *content;
static size_t content_len; static size_t content_len = 0;
static void static void
http_basic_cb(struct evhttp_request *req, void *arg) http_basic_cb(struct evhttp_request *req, void *arg)
@ -85,12 +86,23 @@ http_ref_cb(struct evhttp_request *req, void *arg)
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
struct event_base *base = event_base_new(); struct event_base *base;
struct evhttp *http = evhttp_new(base); struct evhttp *http;
int c; int c;
int use_iocp = 0;
#ifdef WIN32
WSADATA WSAData;
WSAStartup(0x101, &WSAData);
#else
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
return (1);
#endif
base = event_base_new();
unsigned short port = 8080; unsigned short port = 8080;
while ((c = getopt(argc, argv, "p:l:")) != -1) {
while ((c = getopt(argc, argv, "p:l:i")) != -1) {
switch (c) { switch (c) {
case 'p': case 'p':
port = atoi(optarg); port = atoi(optarg);
@ -102,16 +114,20 @@ main(int argc, char **argv)
exit(1); exit(1);
} }
break; break;
#ifdef WIN32
case 'i':
use_iocp = 1;
evthread_use_windows_threads();
event_base_start_iocp(base);
break;
#endif
default: default:
fprintf(stderr, "Illegal argument \"%c\"\n", c); fprintf(stderr, "Illegal argument \"%c\"\n", c);
exit(1); exit(1);
} }
} }
#ifndef WIN32 http = evhttp_new(base);
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
return (1);
#endif
content = malloc(content_len); content = malloc(content_len);
if (content == NULL) { if (content == NULL) {
@ -131,11 +147,16 @@ main(int argc, char **argv)
fprintf(stderr, "/ref - basic content (reference)\n"); fprintf(stderr, "/ref - basic content (reference)\n");
#endif #endif
fprintf(stderr, "Serving %d bytes on port %d\n", fprintf(stderr, "Serving %d bytes on port %d using %s\n",
(int)content_len, port); (int)content_len, port,
use_iocp? "IOCP" : event_base_get_method(base));
evhttp_bind_socket(http, "0.0.0.0", port); evhttp_bind_socket(http, "0.0.0.0", port);
if (use_iocp) {
struct timeval tv={99999999,0};
event_base_loopexit(base, &tv);
}
event_base_dispatch(base); event_base_dispatch(base);
/* NOTREACHED */ /* NOTREACHED */