X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fuclient.git;a=blobdiff_plain;f=uclient-example.c;fp=uclient-example.c;h=65ffc194442310a14a608d22d6aff6b6591e7ec1;hp=3bf8d298c47b1aa9e1920d5ed9717b44af29224f;hb=767d88e3d9c03e56a6eb0b4401bd8cd753215e1b;hpb=e5f35a424a0b69504b0438cb2c4e709b618e3f81 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();