00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
#include "wvhttp.h"
00018
#include "wvstreamlist.h"
00019
#include "wvlog.h"
00020
#include "wvfile.h"
00021
00022
00023 int main(
int argc,
char **argv)
00024 {
00025
WvLog log(
"http", WvLog::Info);
00026
WvURL url(
"http://www.net-itech.com/");
00027
WvHTTPStream http(url);
00028
WvFile out(
"http.out", O_WRONLY | O_TRUNC | O_CREAT);
00029 WvHTTPStream::State last_state = WvHTTPStream::Done;
00030
static char buf[10240];
00031 size_t len;
00032
00033
WvStreamList l;
00034 l.add_after(l.tail, &http,
false);
00035
00036
while (http.
isok() && out.
isok())
00037 {
00038
if (last_state != http.
state)
00039 {
00040
log(
"\nNow in state %s\n", http.
state);
00041 last_state = http.
state;
00042 }
00043
00044
if (l.
select(100))
00045 l.
callback();
00046
00047
if (http.
select(0))
00048 {
00049 len = http.
read(buf,
sizeof(buf));
00050 out.
write(buf, len);
00051
log(
"[%6s]", len);
00052 }
00053 }
00054
00055
if (!http.
isok() && http.
geterr())
00056
log(
"http: %s\n", http.
errstr());
00057
00058
return 0;
00059 }