*** empty log message ***

This commit is contained in:
Mike Goslin 2000-11-17 22:33:00 +00:00
parent 3270809f9b
commit aeb400fc59
3 changed files with 43 additions and 16 deletions

View File

@ -48,3 +48,23 @@ INLINE bool Downloader::
is_download_enabled(void) const { is_download_enabled(void) const {
return _download_enabled; return _download_enabled;
} }
////////////////////////////////////////////////////////////////////
// Function: Downloader::change_buffer_size
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE bool Downloader::
change_buffer_size(int size) {
if (size == _buffer_size)
return true;
nassertr(size > 0, false);
#ifdef HAVE_IPC
_buffer_lock.lock();
#endif
_new_buffer_size = size;
#ifdef HAVE_IPC
_buffer_lock.unlock();
#endif
return true;
}

View File

@ -93,6 +93,8 @@ init(PT(Buffer) buffer) {
_download_enabled = true; _download_enabled = true;
// We need to flush after every write in case we're interrupted // We need to flush after every write in case we're interrupted
_dest_stream.setf(ios::unitbuf, 0); _dest_stream.setf(ios::unitbuf, 0);
_buffer_size = _buffer->get_length();
_new_buffer_size = 0;
#if defined(WIN32) #if defined(WIN32)
WSAData mydata; WSAData mydata;
@ -207,19 +209,6 @@ disconnect_from_server(void) {
_connected = false; _connected = false;
} }
////////////////////////////////////////////////////////////////////
// Function: Downloader::change_buffer_size
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
void Downloader::
change_buffer_size(int size) {
if (_buffer->get_length() == size)
return;
_buffer.clear();
_buffer = new Buffer(size);
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: Downloader::request_download // Function: Downloader::request_download
// Access: Public // Access: Public
@ -526,7 +515,7 @@ download(const string &file_name, Filename file_dest,
// Ensure we have enough room in the buffer to download read_size // Ensure we have enough room in the buffer to download read_size
// If we don't have enough room, write the buffer to disk // If we don't have enough room, write the buffer to disk
if (status._bytes_in_buffer + read_size > downloader_buffer_size) { if (status._bytes_in_buffer + read_size > _buffer_size) {
if (downloader_cat.is_debug()) if (downloader_cat.is_debug())
downloader_cat.debug() downloader_cat.debug()
<< "Downloader::download() - Flushing buffer" << endl; << "Downloader::download() - Flushing buffer" << endl;
@ -758,6 +747,22 @@ write_to_disk(DownloadStatus &status) {
status.reset(); status.reset();
// Now see if we need to adjust the buffer size
if (_new_buffer_size > 0) {
#ifdef HAVE_IPC
_buffer_lock.lock();
#endif
_buffer.clear();
_buffer = new Buffer(_new_buffer_size);
_buffer_size = _new_buffer_size;
_new_buffer_size = 0;
#ifdef HAVE_IPC
_buffer_lock.unlock();
#endif
}
return true; return true;
} }

View File

@ -46,12 +46,11 @@ PUBLISHED:
int last_byte, int total_bytes, int last_byte, int total_bytes,
bool partial_content = true); bool partial_content = true);
void change_buffer_size(int size);
INLINE void set_bandwidth(float bytes); INLINE void set_bandwidth(float bytes);
INLINE float get_bandwidth(void) const; INLINE float get_bandwidth(void) const;
INLINE void enable_download(bool val); INLINE void enable_download(bool val);
INLINE bool is_download_enabled(void) const; INLINE bool is_download_enabled(void) const;
INLINE bool change_buffer_size(int size);
private: private:
class DownloadStatus { class DownloadStatus {
@ -100,6 +99,7 @@ private:
#ifdef HAVE_IPC #ifdef HAVE_IPC
mutex _bandwidth_frequency_lock; mutex _bandwidth_frequency_lock;
mutex _buffer_lock;
#endif #endif
int _socket; int _socket;
@ -107,6 +107,8 @@ private:
float _bandwidth; float _bandwidth;
bool _download_enabled; bool _download_enabled;
ofstream _dest_stream; ofstream _dest_stream;
int _new_buffer_size;
int _buffer_size;
string _server_name; string _server_name;
struct sockaddr_in _sin; struct sockaddr_in _sin;