You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2020/10/01 07:32:41 UTC
[incubator-nuttx-apps] 03/04: examples/wget: Adapt to the new
webclient api
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
commit b0e7b0011b0da4131e7fe4e21d7eb5eff6e95e09
Author: YAMAMOTO Takashi <ya...@midokura.com>
AuthorDate: Tue Sep 29 11:33:11 2020 +0900
examples/wget: Adapt to the new webclient api
tested as: "nsh> wget http://example.com/"
---
examples/wget/wget_main.c | 25 +++++++++++++++++++++----
1 file changed, 21 insertions(+), 4 deletions(-)
diff --git a/examples/wget/wget_main.c b/examples/wget/wget_main.c
index 3b634d9..4de57b8 100644
--- a/examples/wget/wget_main.c
+++ b/examples/wget/wget_main.c
@@ -94,10 +94,18 @@ static char g_iobuffer[512];
* Name: callback
****************************************************************************/
-static void callback(FAR char **buffer, int offset, int datend,
+static int callback(FAR char **buffer, int offset, int datend,
FAR int *buflen, FAR void *arg)
{
- write(1, &((*buffer)[offset]), datend - offset);
+ ssize_t written = write(1, &((*buffer)[offset]), datend - offset);
+ if (written == -1)
+ {
+ return -errno;
+ }
+
+ /* Revisit: Do we want to check and report short writes? */
+
+ return 0;
}
/****************************************************************************
@@ -152,14 +160,23 @@ int main(int argc, FAR char *argv[])
/* Then start the server */
+ struct webclient_context ctx;
+ webclient_set_defaults(&ctx);
+ ctx.method = "GET";
+ ctx.buffer = g_iobuffer;
+ ctx.buflen = 512;
+ ctx.sink_callback = callback;
+ ctx.sink_callback_arg = NULL;
if (argc > 1)
{
- wget(argv[1], g_iobuffer, 512, callback, NULL);
+ ctx.url = argv[1];
}
else
{
- wget(CONFIG_EXAMPLES_WGET_URL, g_iobuffer, 512, callback, NULL);
+ ctx.url = CONFIG_EXAMPLES_WGET_URL;
}
+ webclient_perform(&ctx);
+
return 0;
}