mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 09:52:27 -04:00
*** empty log message ***
This commit is contained in:
parent
7bfdd75113
commit
2bfcda82d4
@ -82,7 +82,7 @@ Downloader::
|
|||||||
~Downloader() {
|
~Downloader() {
|
||||||
if (_connected)
|
if (_connected)
|
||||||
disconnect_from_server();
|
disconnect_from_server();
|
||||||
delete _buffer;
|
_buffer.clear();
|
||||||
if (_current_status != NULL)
|
if (_current_status != NULL)
|
||||||
delete _current_status;
|
delete _current_status;
|
||||||
}
|
}
|
||||||
@ -260,7 +260,7 @@ fast_receive(int socket, DownloadStatus *status, int rec_size) {
|
|||||||
status->_next_in += ret;
|
status->_next_in += ret;
|
||||||
status->_bytes_in_buffer += ret;
|
status->_bytes_in_buffer += ret;
|
||||||
status->_total_bytes += ret;
|
status->_total_bytes += ret;
|
||||||
return ret;
|
return FR_success;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -401,16 +401,15 @@ run(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Attempt to receive the bytes from the socket
|
// 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();
|
_tlast = _clock.get_real_time();
|
||||||
|
|
||||||
// Check for end of file
|
// Check for end of file
|
||||||
if (bytes_read == 0) {
|
if (fret == FR_eof) {
|
||||||
if (_got_any_data == true) {
|
if (_got_any_data == true) {
|
||||||
if (_current_status->_bytes_in_buffer > 0) {
|
if (_current_status->_bytes_in_buffer > 0) {
|
||||||
if (write_to_disk(_current_status) == false)
|
if (write_to_disk(_current_status) == false)
|
||||||
return DS_error_write;
|
return DS_error_write;
|
||||||
ret = DS_write;
|
|
||||||
}
|
}
|
||||||
return DS_success;
|
return DS_success;
|
||||||
} else {
|
} else {
|
||||||
@ -419,7 +418,12 @@ run(void) {
|
|||||||
<< "Downloader::run() - Got 0 bytes" << endl;
|
<< "Downloader::run() - Got 0 bytes" << endl;
|
||||||
return DS_ok;
|
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;
|
return DS_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,3 +79,10 @@
|
|||||||
|
|
||||||
#end bin_target
|
#end bin_target
|
||||||
|
|
||||||
|
#begin bin_target
|
||||||
|
#define TARGET test_downloader
|
||||||
|
|
||||||
|
#define SOURCES \
|
||||||
|
test_downloader.cxx
|
||||||
|
|
||||||
|
#end bin_target
|
||||||
|
35
panda/src/downloadertools/test_downloader.cxx
Normal file
35
panda/src/downloadertools/test_downloader.cxx
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#include <pandabase.h>
|
||||||
|
#include <downloader.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char *argv[]) {
|
||||||
|
|
||||||
|
if (argc < 4) {
|
||||||
|
cerr << "Usage: test_downloader <server> <source file> <dest file>"
|
||||||
|
<< 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;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user