summaryrefslogtreecommitdiffstats
path: root/test/httpget.c
diff options
context:
space:
mode:
authorTimo Teras <timo.teras@iki.fi>2009-11-26 09:35:49 +0200
committerTimo Teras <timo.teras@iki.fi>2009-11-26 09:37:24 +0200
commitaa530f352b0410150bfe94c821ae32c1378b9d02 (patch)
treefb27f277db0c7feaaf12ce43169d3b0b44e95c0f /test/httpget.c
parent4db830052d941d9c6de281bc9a2f6ac212c59ad8 (diff)
downloadlibtf-aa530f352b0410150bfe94c821ae32c1378b9d02.tar.bz2
libtf-aa530f352b0410150bfe94c821ae32c1378b9d02.tar.xz
libtf: stackable timeouts
instead of having per-function argument, use a push/pop mechanism: - multiple timers inside fiber use only one heap entry - easy to chain multiple possibly blocking operations inside one timeout block
Diffstat (limited to 'test/httpget.c')
-rw-r--r--test/httpget.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/test/httpget.c b/test/httpget.c
index c1e37a3..fed6c06 100644
--- a/test/httpget.c
+++ b/test/httpget.c
@@ -15,7 +15,7 @@ static void ping_fiber(void *ptr)
struct tf_sockaddr host;
struct tf_fd fd;
char buf[128];
- int bytes = 0, r = 0;
+ int bytes = 0, r;
const char *req = "GET / HTTP/1.0\r\n\r\n";
printf("Lookup %s\n", ctx->hostname);
@@ -23,16 +23,19 @@ static void ping_fiber(void *ptr)
host.u.in.sin_addr.s_addr = inet_addr(ctx->hostname);
host.u.in.sin_port = htons(80);
- if (tf_socket(&fd, AF_INET, SOCK_STREAM, 0) < 0)
+ r = tf_socket(&fd, AF_INET, SOCK_STREAM, 0);
+ if (r < 0)
goto err;
- if ((r = tf_connect(&fd, &host, 10000)) < 0)
+ r = tf_timed(tf_connect(&fd, &host), 10000);
+ if (r < 0)
goto err_close;
- if ((r = tf_write_fully(&fd, req, strlen(req), 10000)) < 0)
+ r = tf_write_fully(&fd, req, strlen(req));
+ if (r < 0)
goto err_close;
- while ((r = tf_read(&fd, buf, sizeof(buf), 10000)) > 0)
+ while ((r = tf_read(&fd, buf, sizeof(buf))) > 0)
bytes += r;
err_close:
tf_close(&fd);