mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-14 06:49:35 -04:00
sample/http-connect: don't use assert() to make it work with NDEBUG
Otherwise it will not work for cmake release target type.
This commit is contained in:
parent
9f0bff3f68
commit
6dc71e70dc
@ -4,10 +4,15 @@
|
||||
#include <event2/buffer.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
|
||||
#define VERIFY(cond) do { \
|
||||
if (!(cond)) { \
|
||||
fprintf(stderr, "[error] %s\n", #cond); \
|
||||
} \
|
||||
} while (0); \
|
||||
|
||||
struct connect_base
|
||||
{
|
||||
struct evhttp_connection *evcon;
|
||||
@ -16,7 +21,7 @@ struct connect_base
|
||||
|
||||
static void get_cb(struct evhttp_request *req, void *arg)
|
||||
{
|
||||
assert(req);
|
||||
VERIFY(req);
|
||||
evbuffer_write(req->input_buffer, STDOUT_FILENO);
|
||||
}
|
||||
|
||||
@ -28,11 +33,11 @@ static void connect_cb(struct evhttp_request *proxy_req, void *arg)
|
||||
struct evhttp_connection *evcon = base->evcon;
|
||||
struct evhttp_uri *location = base->location;
|
||||
|
||||
assert(proxy_req);
|
||||
VERIFY(proxy_req);
|
||||
if (evcon) {
|
||||
struct evhttp_request *req = evhttp_request_new(get_cb, NULL);
|
||||
evhttp_add_header(req->output_headers, "Connection", "close");
|
||||
assert(!evhttp_make_request(evcon, req, EVHTTP_REQ_GET,
|
||||
VERIFY(!evhttp_make_request(evcon, req, EVHTTP_REQ_GET,
|
||||
evhttp_uri_join(location, buffer, PATH_MAX)));
|
||||
}
|
||||
}
|
||||
@ -58,8 +63,8 @@ int main(int argc, const char **argv)
|
||||
|
||||
{
|
||||
proxy = evhttp_uri_parse(argv[1]);
|
||||
assert(evhttp_uri_get_host(proxy));
|
||||
assert(evhttp_uri_get_port(proxy) > 0);
|
||||
VERIFY(evhttp_uri_get_host(proxy));
|
||||
VERIFY(evhttp_uri_get_port(proxy) > 0);
|
||||
}
|
||||
{
|
||||
host_port = evhttp_uri_parse(argv[2]);
|
||||
@ -68,8 +73,8 @@ int main(int argc, const char **argv)
|
||||
evhttp_uri_set_path(host_port, NULL);
|
||||
evhttp_uri_set_query(host_port, NULL);
|
||||
evhttp_uri_set_fragment(host_port, NULL);
|
||||
assert(evhttp_uri_get_host(host_port));
|
||||
assert(evhttp_uri_get_port(host_port) > 0);
|
||||
VERIFY(evhttp_uri_get_host(host_port));
|
||||
VERIFY(evhttp_uri_get_port(host_port) > 0);
|
||||
}
|
||||
{
|
||||
location = evhttp_uri_parse(argv[2]);
|
||||
@ -79,14 +84,14 @@ int main(int argc, const char **argv)
|
||||
evhttp_uri_set_port(location, -1);
|
||||
}
|
||||
|
||||
assert(base = event_base_new());
|
||||
assert(evcon = evhttp_connection_base_new(base, NULL,
|
||||
VERIFY(base = event_base_new());
|
||||
VERIFY(evcon = evhttp_connection_base_new(base, NULL,
|
||||
evhttp_uri_get_host(proxy), evhttp_uri_get_port(proxy)));
|
||||
connect_base = (struct connect_base){
|
||||
.evcon = evcon,
|
||||
.location = location,
|
||||
};
|
||||
assert(req = evhttp_request_new(connect_cb, &connect_base));
|
||||
VERIFY(req = evhttp_request_new(connect_cb, &connect_base));
|
||||
|
||||
evhttp_add_header(req->output_headers, "Connection", "keep-alive");
|
||||
evhttp_add_header(req->output_headers, "Proxy-Connection", "keep-alive");
|
||||
|
Loading…
x
Reference in New Issue
Block a user