Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.

Commit

Permalink
Eat our own dogfood (use_thread_wexit())
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFrench committed Sep 9, 2017
1 parent e0a48e1 commit ea37928
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 16 deletions.
4 changes: 2 additions & 2 deletions examples/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ main(int argc, char ** argv) {
evhtp_callback_set_hook(cb_6, evhtp_hook_on_headers, test_regex_hdrs_cb, NULL);
#endif

evhtp_callback_set_hook(cb_10, evhtp_hook_on_headers, set_max_body, NULL);
evhtp_callback_set_hook(cb_10, evhtp_hook_on_headers, set_max_body, NULL);

/* set a default request handler */
evhtp_set_gencb(htp, test_default_cb, "foobarbaz");
Expand Down Expand Up @@ -648,7 +648,7 @@ main(int argc, char ** argv) {

#ifndef EVHTP_DISABLE_EVTHR
if (use_threads) {
evhtp_use_threads(htp, NULL, num_threads, NULL);
evhtp_use_threads_wexit(htp, NULL, NULL, num_threads, NULL);
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion examples/test_basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ main(int argc, char ** argv) {
evhtp_set_cb(htp, "/1/ping.json", testcb, "two");
evhtp_set_cb(htp, "/issue161", issue161cb, NULL);
#ifndef EVHTP_DISABLE_EVTHR
evhtp_use_threads(htp, NULL, 8, NULL);
evhtp_use_threads_wexit(htp, NULL, NULL, 8, NULL);
#endif
evhtp_bind_socket(htp, "0.0.0.0", 8081, 2048);

Expand Down
27 changes: 16 additions & 11 deletions examples/test_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,46 @@
#include <evhtp.h>

static void
request_cb(evhtp_request_t * req, void * arg) {
request_cb(evhtp_request_t * req, void * arg)
{
printf("hi %zu\n", evbuffer_get_length(req->buffer_in));
}

static evhtp_res
print_data(evhtp_request_t * req, evbuf_t * buf, void * arg) {
print_data(evhtp_request_t * req, evbuf_t * buf, void * arg)
{
printf("Got %zu bytes\n", evbuffer_get_length(buf));

return EVHTP_RES_OK;
}

static evhtp_res
print_new_chunk_len(evhtp_request_t * req, uint64_t len, void * arg) {
print_new_chunk_len(evhtp_request_t * req, uint64_t len, void * arg)
{
printf("started new chunk, %" PRIu64 " bytes\n", len);

return EVHTP_RES_OK;
}

static evhtp_res
print_chunk_complete(evhtp_request_t * req, void * arg) {
print_chunk_complete(evhtp_request_t * req, void * arg)
{
printf("ended a single chunk\n");

return EVHTP_RES_OK;
}

static evhtp_res
print_chunks_complete(evhtp_request_t * req, void * arg) {
print_chunks_complete(evhtp_request_t * req, void * arg)
{
printf("all chunks read\n");

return EVHTP_RES_OK;
}

int
main(int argc, char ** argv) {
main(int argc, char ** argv)
{
evbase_t * evbase;
evhtp_connection_t * conn;
evhtp_request_t * request;
Expand All @@ -49,10 +55,10 @@ main(int argc, char ** argv) {
conn = evhtp_connection_new(evbase, "75.126.169.52", 80);
request = evhtp_request_new(request_cb, evbase);

evhtp_set_hook(&request->hooks, evhtp_hook_on_read, print_data, evbase);
evhtp_set_hook(&request->hooks, evhtp_hook_on_new_chunk, print_new_chunk_len, NULL);
evhtp_set_hook(&request->hooks, evhtp_hook_on_chunk_complete, print_chunk_complete, NULL);
evhtp_set_hook(&request->hooks, evhtp_hook_on_chunks_complete, print_chunks_complete, NULL);
evhtp_request_set_hook(request, evhtp_hook_on_read, print_data, evbase);
evhtp_request_set_hook(request, evhtp_hook_on_new_chunk, print_new_chunk_len, NULL);
evhtp_request_set_hook(request, evhtp_hook_on_chunk_complete, print_chunk_complete, NULL);
evhtp_request_set_hook(request, evhtp_hook_on_chunks_complete, print_chunks_complete, NULL);

evhtp_headers_add_header(request->headers_out,
evhtp_header_new("Host", "ieatfood.net", 0, 0));
Expand All @@ -68,4 +74,3 @@ main(int argc, char ** argv) {

return 0;
}

2 changes: 1 addition & 1 deletion examples/test_perf.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ main(int argc, char ** argv)
#ifndef EVHTP_DISABLE_EVTHR
if (num_threads > 0)
{
evhtp_assert(evhtp_use_threads(htp, NULL, num_threads, NULL) != -1);
evhtp_assert(evhtp_use_threads_wexit(htp, NULL, NULL, num_threads, NULL) != -1);
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion examples/test_proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ main(int argc, char ** argv) {
#endif
#endif

evhtp_use_threads(evhtp, init_thread_cb, 8, NULL);
evhtp_use_threads_wexit(evhtp, init_thread_cb, NULL, 8, NULL);
#ifndef WIN32
ev_sigterm = evsignal_new(evbase, SIGTERM, sigterm_cb, evbase);
evsignal_add(ev_sigterm, NULL);
Expand Down

0 comments on commit ea37928

Please sign in to comment.