mirror of
https://github.com/wg/wrk
synced 2025-01-10 00:32:56 +08:00
stop after receiving SIGINT
This commit is contained in:
parent
5496c588eb
commit
86a23c6beb
2
Makefile
2
Makefile
@ -4,7 +4,7 @@ LIBS := -lpthread -lm
|
|||||||
TARGET := $(shell uname -s | tr [A-Z] [a-z] 2>/dev/null || echo unknown)
|
TARGET := $(shell uname -s | tr [A-Z] [a-z] 2>/dev/null || echo unknown)
|
||||||
|
|
||||||
ifeq ($(TARGET), sunos)
|
ifeq ($(TARGET), sunos)
|
||||||
CFLAGS += -D_PTHREADS
|
CFLAGS += -D_PTHREADS -D_POSIX_C_SOURCE=200112L
|
||||||
LIBS += -lsocket
|
LIBS += -lsocket
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
16
src/wrk.c
16
src/wrk.c
@ -51,6 +51,12 @@ static const struct http_parser_settings parser_settings = {
|
|||||||
.on_message_complete = request_complete
|
.on_message_complete = request_complete
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static volatile sig_atomic_t stop = 0;
|
||||||
|
|
||||||
|
static void handler(int sig) {
|
||||||
|
stop = 1;
|
||||||
|
}
|
||||||
|
|
||||||
static void usage() {
|
static void usage() {
|
||||||
printf("Usage: wrk <options> <url> \n"
|
printf("Usage: wrk <options> <url> \n"
|
||||||
" Options: \n"
|
" Options: \n"
|
||||||
@ -118,6 +124,7 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
signal(SIGPIPE, SIG_IGN);
|
signal(SIGPIPE, SIG_IGN);
|
||||||
|
signal(SIGINT, SIG_IGN);
|
||||||
cfg.addr = *addr;
|
cfg.addr = *addr;
|
||||||
request.buf = format_request(host, port, path, headers);
|
request.buf = format_request(host, port, path, headers);
|
||||||
request.size = strlen(request.buf);
|
request.size = strlen(request.buf);
|
||||||
@ -142,6 +149,13 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct sigaction sa = {
|
||||||
|
.sa_handler = handler,
|
||||||
|
.sa_flags = 0,
|
||||||
|
};
|
||||||
|
sigfillset(&sa.sa_mask);
|
||||||
|
sigaction(SIGINT, &sa, NULL);
|
||||||
|
|
||||||
printf("Making %"PRIu64" requests to %s\n", cfg.requests, url);
|
printf("Making %"PRIu64" requests to %s\n", cfg.requests, url);
|
||||||
printf(" %"PRIu64" threads and %"PRIu64" connections\n", cfg.threads, cfg.connections);
|
printf(" %"PRIu64" threads and %"PRIu64" connections\n", cfg.threads, cfg.connections);
|
||||||
|
|
||||||
@ -323,7 +337,7 @@ static int check_timeouts(aeEventLoop *loop, long long id, void *data) {
|
|||||||
errors += thread->errors.write;
|
errors += thread->errors.write;
|
||||||
errors += thread->errors.timeout;
|
errors += thread->errors.timeout;
|
||||||
|
|
||||||
if (errors >= cfg.errors) {
|
if (stop || errors >= cfg.errors) {
|
||||||
aeStop(loop);
|
aeStop(loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user