diff options
author | Andreas Baumann <abaumann@yahoo.com> | 2012-07-13 15:26:57 +0200 |
---|---|---|
committer | Andreas Baumann <abaumann@yahoo.com> | 2012-07-13 15:26:57 +0200 |
commit | 48f536bd7d4a7dece336a5588d17160b66949aaf (patch) | |
tree | c05bea4e8b21aa09fa421a2cb388aaed4ed34e5f /tests/libfetch | |
parent | b00e07aecce60a9c975aa8f2cf2f085c5ea34783 (diff) | |
download | crawler-48f536bd7d4a7dece336a5588d17160b66949aaf.tar.gz crawler-48f536bd7d4a7dece336a5588d17160b66949aaf.tar.bz2 |
-
Diffstat (limited to 'tests/libfetch')
-rw-r--r-- | tests/libfetch/test2.cpp | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/tests/libfetch/test2.cpp b/tests/libfetch/test2.cpp index 2a49f85..9c60924 100644 --- a/tests/libfetch/test2.cpp +++ b/tests/libfetch/test2.cpp @@ -66,16 +66,20 @@ class libfetch_istream : public istream libfetch_istream( const char *url ); ~libfetch_istream( ); + string lastErrMsg( ) const; + private: fetchIO *m_io; libfetch_buffer *m_buf; }; libfetch_istream::libfetch_istream( const char *url ) + : m_io( 0 ), m_buf( 0 ) { m_io = fetchGetURL( url, "" ); if( m_io == NULL ) { - // TODO: handle error bit + setstate( badbit ); + return; } m_buf = new libfetch_buffer( m_io ); rdbuf( m_buf ); @@ -83,8 +87,13 @@ libfetch_istream::libfetch_istream( const char *url ) libfetch_istream::~libfetch_istream( ) { - delete m_buf; - fetchIO_close( m_io ); + if( m_buf ) delete m_buf; + if( m_io ) fetchIO_close( m_io ); +} + +string libfetch_istream::lastErrMsg( ) const +{ + return fetchLastErrString; } int main( int argc, char *argv[] ) @@ -103,7 +112,12 @@ int main( int argc, char *argv[] ) libfetch_istream is( urlstring ); string s; - while( !is.eof( ) ) { + if( !is.good( ) ) { + cerr << "ERROR in libfetch input stream: " << is.lastErrMsg( ) << endl; + return 1; + } + + while( is.good( ) && !is.eof( ) ) { getline( is, s ); cout << s << endl; } |