From 2bfcda82d41557caa28d9ce98c497b6dc56bb6af Mon Sep 17 00:00:00 2001 From: Mike Goslin Date: Wed, 13 Dec 2000 23:04:49 +0000 Subject: [PATCH] *** empty log message *** --- panda/src/downloader/downloader.cxx | 16 +++++---- panda/src/downloadertools/Sources.pp | 7 ++++ panda/src/downloadertools/test_downloader.cxx | 35 +++++++++++++++++++ 3 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 panda/src/downloadertools/test_downloader.cxx diff --git a/panda/src/downloader/downloader.cxx b/panda/src/downloader/downloader.cxx index a64e555c15..ff3fe93016 100644 --- a/panda/src/downloader/downloader.cxx +++ b/panda/src/downloader/downloader.cxx @@ -82,7 +82,7 @@ Downloader:: ~Downloader() { if (_connected) disconnect_from_server(); - delete _buffer; + _buffer.clear(); if (_current_status != NULL) delete _current_status; } @@ -260,7 +260,7 @@ fast_receive(int socket, DownloadStatus *status, int rec_size) { status->_next_in += ret; status->_bytes_in_buffer += ret; status->_total_bytes += ret; - return ret; + return FR_success; } //////////////////////////////////////////////////////////////////// @@ -401,16 +401,15 @@ run(void) { } // Attempt to receive the bytes from the socket - int bytes_read = fast_receive(_socket, _current_status, _receive_size); + int fret = fast_receive(_socket, _current_status, _receive_size); _tlast = _clock.get_real_time(); // Check for end of file - if (bytes_read == 0) { + if (fret == FR_eof) { if (_got_any_data == true) { if (_current_status->_bytes_in_buffer > 0) { if (write_to_disk(_current_status) == false) return DS_error_write; - ret = DS_write; } return DS_success; } else { @@ -419,7 +418,12 @@ run(void) { << "Downloader::run() - Got 0 bytes" << endl; return DS_ok; } - } else if (bytes_read < 0) { + } else if (fret == FR_no_data) { + if (downloader_cat.is_debug()) + downloader_cat.debug() + << "Downloader::run() - No data" << endl; + return DS_ok; + } else if (fret < 0) { return DS_error; } diff --git a/panda/src/downloadertools/Sources.pp b/panda/src/downloadertools/Sources.pp index 60a572f2f7..712ca80e66 100644 --- a/panda/src/downloadertools/Sources.pp +++ b/panda/src/downloadertools/Sources.pp @@ -79,3 +79,10 @@ #end bin_target +#begin bin_target + #define TARGET test_downloader + + #define SOURCES \ + test_downloader.cxx + +#end bin_target diff --git a/panda/src/downloadertools/test_downloader.cxx b/panda/src/downloadertools/test_downloader.cxx new file mode 100644 index 0000000000..d41522d9d3 --- /dev/null +++ b/panda/src/downloadertools/test_downloader.cxx @@ -0,0 +1,35 @@ +#include +#include + +int +main(int argc, char *argv[]) { + + if (argc < 4) { + cerr << "Usage: test_downloader " + << endl; + return 0; + } + + string server_name = argv[1]; + Filename src_file = argv[2]; + Filename dest_file = argv[3]; + + Downloader dl; + if (dl.connect_to_server(server_name) == false) + return 0; + + int ret = dl.initiate(src_file, dest_file); + if (ret < 0) + return 0; + + for (;;) { + ret = dl.run(); + if (ret == Downloader::DS_success) { + return 1; + } else if (ret == Downloader::DS_write) { + cerr << "bytes per second: " << dl.get_bytes_per_second() << endl; + } else if (ret < 0) + return 0; + } + return 0; +}