From: Felix Fietkau Date: Sun, 4 May 2014 16:34:40 +0000 (+0200) Subject: example: create only one request X-Git-Url: https://git.librecmc.org/?p=oweals%2Fuclient.git;a=commitdiff_plain;h=767d88e3d9c03e56a6eb0b4401bd8cd753215e1b example: create only one request Signed-off-by: Felix Fietkau --- diff --git a/uclient-example.c b/uclient-example.c index 3bf8d29..65ffc19 100644 --- a/uclient-example.c +++ b/uclient-example.c @@ -77,26 +77,17 @@ static void msg_connecting(struct uclient *cl) fprintf(stderr, "Connecting to %s %s:%d\n", cl->url->host, addr, port); } -static void example_request_sm(struct uclient *cl) +static void init_request(struct uclient *cl) { - static int i = 0; - - switch (i++) { - case 0: - uclient_connect(cl); - msg_connecting(cl); - uclient_http_set_request_type(cl, "HEAD"); - uclient_request(cl); - break; - case 1: - uclient_connect(cl); - uclient_http_set_request_type(cl, "GET"); - uclient_request(cl); - break; - default: - uloop_end(); - break; - }; + uclient_connect(cl); + msg_connecting(cl); + uclient_http_set_request_type(cl, "GET"); + uclient_request(cl); +} + +static void request_done(struct uclient *cl) +{ + uloop_end(); } static void example_eof(struct uclient *cl) @@ -109,14 +100,15 @@ static void example_eof(struct uclient *cl) } retries = 0; - example_request_sm(cl); + request_done(cl); } static void example_error(struct uclient *cl, int code) { if (!quiet) fprintf(stderr, "Error %d!\n", code); - example_request_sm(cl); + + request_done(cl); } static const struct uclient_cb cb = { @@ -225,7 +217,7 @@ int main(int argc, char **argv) if (ssl_ctx) uclient_http_set_ssl_ctx(cl, ssl_ops, ssl_ctx, verify); - example_request_sm(cl); + init_request(cl); uloop_run(); uloop_done();