downloader is now superceded by HTTPClient
This commit is contained in:
parent
ebc6b3f7d0
commit
5dcf02624d
|
|
@ -25,7 +25,7 @@
|
|||
multiplexStreamBuf.I multiplexStreamBuf.h \
|
||||
socketStream.h socketStream.I \
|
||||
urlSpec.I urlSpec.h \
|
||||
$[if $[HAVE_NET], downloadDb.I downloadDb.h downloader.I downloader.h] \
|
||||
$[if $[HAVE_NET], downloadDb.I downloadDb.h] \
|
||||
$[if $[HAVE_ZLIB], decompressor.h download_utils.h] \
|
||||
$[if $[HAVE_CRYPTO], patcher.cxx patcher.h patcher.I]
|
||||
|
||||
|
|
@ -43,7 +43,7 @@
|
|||
multiplexStream.cxx multiplexStreamBuf.cxx \
|
||||
socketStream.cxx \
|
||||
urlSpec.cxx \
|
||||
$[if $[HAVE_NET], downloadDb.cxx downloader.cxx] \
|
||||
$[if $[HAVE_NET], downloadDb.cxx] \
|
||||
$[if $[HAVE_ZLIB], decompressor.cxx download_utils.cxx]
|
||||
|
||||
#define INSTALL_HEADERS \
|
||||
|
|
@ -55,7 +55,6 @@
|
|||
config_downloader.h \
|
||||
decompressor.h \
|
||||
download_utils.h downloadDb.h downloadDb.I \
|
||||
downloader.h downloader.I \
|
||||
extractor.h \
|
||||
httpClient.I httpClient.h \
|
||||
httpChannel.I httpChannel.h \
|
||||
|
|
|
|||
|
|
@ -1,168 +0,0 @@
|
|||
// Filename: downloader.I
|
||||
// Created by: mike (09Jan97)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
|
||||
//
|
||||
// All use of this software is subject to the terms of the Panda 3d
|
||||
// Software license. You should have received a copy of this license
|
||||
// along with this source code; you will also find a current copy of
|
||||
// the license at http://www.panda3d.org/license.txt .
|
||||
//
|
||||
// To contact the maintainers of this program write to
|
||||
// panda3d@yahoogroups.com .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "config_downloader.h"
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Downloader::get_file_size
|
||||
// Access: Published
|
||||
// Description: Returns the size of the file currently being
|
||||
// downloaded, in bytes, if it is known. Returns 0 if
|
||||
// the file size is not known.
|
||||
//
|
||||
// After a call to initiate(), this will return 0; at
|
||||
// some later point, when the first response from the
|
||||
// server is read, it may return the actual size of the
|
||||
// file if the server told us. It is possible the
|
||||
// server will not tell us the size of the file, in
|
||||
// which case this will always return 0.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE int Downloader::
|
||||
get_file_size() const {
|
||||
return _file_size;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Downloader::set_frequency
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Downloader::
|
||||
set_frequency(float frequency) {
|
||||
nassertv(frequency > 0.0);
|
||||
if (_frequency != frequency) {
|
||||
_frequency = frequency;
|
||||
_recompute_buffer = true;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Downloader::get_frequency
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE float Downloader::
|
||||
get_frequency(void) const {
|
||||
return _frequency;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Downloader::set_byte_rate
|
||||
// Access: Public
|
||||
// Description: Note: modem speeds are reported in bits, so you
|
||||
// need to convert!
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Downloader::
|
||||
set_byte_rate(float bytes) {
|
||||
nassertv(bytes > 0.0);
|
||||
if (_byte_rate != bytes) {
|
||||
_byte_rate = bytes;
|
||||
_recompute_buffer = true;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Downloader::get_byte_rate
|
||||
// Access: Public
|
||||
// Description: Returns byte rate in bytes.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE float Downloader::
|
||||
get_byte_rate(void) const {
|
||||
return _byte_rate;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Downloader::set_disk_write_frequency
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Downloader::
|
||||
set_disk_write_frequency(int frequency) {
|
||||
nassertv(frequency > 0);
|
||||
if (_disk_write_frequency != frequency) {
|
||||
_disk_write_frequency = frequency;
|
||||
_recompute_buffer = true;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Downloader::get_disk_write_frequency
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE int Downloader::
|
||||
get_disk_write_frequency(void) const {
|
||||
return _disk_write_frequency;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Downloader::get_bytes_written
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE int Downloader::
|
||||
get_bytes_written(void) const {
|
||||
if (_ever_initiated == false) {
|
||||
downloader_cat.warning()
|
||||
<< "Downloader::get_bytes_written() - Download has not been "
|
||||
<< "initiated" << endl;
|
||||
return 0;
|
||||
}
|
||||
if (_current_status != NULL)
|
||||
return _current_status->_total_bytes_written;
|
||||
else
|
||||
return _total_bytes_written;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Downloader::get_bytes_requested
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE int Downloader::
|
||||
get_bytes_requested(void) const {
|
||||
if (_ever_initiated == false) {
|
||||
downloader_cat.warning()
|
||||
<< "Downloader::get_bytes_requested() - Download has not been "
|
||||
<< "initiated" << endl;
|
||||
return 0;
|
||||
}
|
||||
if (_current_status != NULL)
|
||||
return _current_status->_total_bytes_requested;
|
||||
else
|
||||
return _total_bytes_requested;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Downloader::get_bytes_per_second
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE float Downloader::
|
||||
get_bytes_per_second(void) const {
|
||||
if (_ever_initiated == false) {
|
||||
downloader_cat.warning()
|
||||
<< "Downloader::get_bytes_per_second() - Download has not been "
|
||||
<< "initiated" << endl;
|
||||
return 0.0;
|
||||
}
|
||||
nassertr(_tlast - _tfirst > 0.0, 0.0);
|
||||
nassertr(_current_status != NULL, 0.0);
|
||||
return (float)((double)_current_status->_total_bytes / (_tlast - _tfirst));
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,157 +0,0 @@
|
|||
// Filename: downloader.h
|
||||
// Created by: mike (09Jan97)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
|
||||
//
|
||||
// All use of this software is subject to the terms of the Panda 3d
|
||||
// Software license. You should have received a copy of this license
|
||||
// along with this source code; you will also find a current copy of
|
||||
// the license at http://www.panda3d.org/license.txt .
|
||||
//
|
||||
// To contact the maintainers of this program write to
|
||||
// panda3d@yahoogroups.com .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
#ifndef DOWNLOADER_H
|
||||
#define DOWNLOADER_H
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Includes
|
||||
////////////////////////////////////////////////////////////////////
|
||||
#include <pandabase.h>
|
||||
#include <notify.h>
|
||||
#include <filename.h>
|
||||
#include <buffer.h>
|
||||
#include <pointerTo.h>
|
||||
#include <clockObject.h>
|
||||
|
||||
#if defined(WIN32_VC)
|
||||
#include <winsock.h>
|
||||
#else
|
||||
#include <netinet/in.h> // Irix seems to require this one for resolv.h.
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <resolv.h>
|
||||
#endif
|
||||
|
||||
class URLSpec;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : Downloader
|
||||
// Description : This object is used to manage downloading of data
|
||||
// from an HTTP server as a background task within a
|
||||
// single-threaded network application. The class can
|
||||
// download a small piece at a time when run() is called
|
||||
// from time to time; it is designed to both limit time
|
||||
// spent in the run() call as well as limiting network
|
||||
// bandwidth utilized by the download, so that CPU
|
||||
// cycles and bandwidth are still available to the
|
||||
// application for other purposes.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
class EXPCL_PANDAEXPRESS Downloader {
|
||||
PUBLISHED:
|
||||
Downloader(void);
|
||||
virtual ~Downloader(void);
|
||||
|
||||
int connect_to_server_by_proxy(const URLSpec &proxy, const string &server_name);
|
||||
int connect_to_server(const string &name, uint port=80);
|
||||
void disconnect_from_server(void);
|
||||
|
||||
int initiate(const string &file_name, Filename file_dest);
|
||||
int initiate(const string &file_name, Filename file_dest,
|
||||
int first_byte, int last_byte, int total_bytes,
|
||||
bool partial_content = true);
|
||||
int initiate(const string &file_name);
|
||||
INLINE int get_file_size() const;
|
||||
|
||||
int run(void);
|
||||
|
||||
bool get_ramfile(Ramfile &rfile);
|
||||
|
||||
INLINE void set_frequency(float frequency);
|
||||
INLINE float get_frequency(void) const;
|
||||
INLINE void set_byte_rate(float bytes);
|
||||
INLINE float get_byte_rate(void) const;
|
||||
INLINE void set_disk_write_frequency(int frequency);
|
||||
INLINE int get_disk_write_frequency(void) const;
|
||||
INLINE int get_bytes_written(void) const;
|
||||
INLINE int get_bytes_requested(void) const;
|
||||
INLINE float get_bytes_per_second(void) const;
|
||||
|
||||
void cleanup(void);
|
||||
|
||||
|
||||
private:
|
||||
class DownloadStatus {
|
||||
public:
|
||||
DownloadStatus(char *buffer, int first_byte, int last_byte,
|
||||
int total_bytes, bool partial_content);
|
||||
void reset(void);
|
||||
|
||||
public:
|
||||
bool _first_line_complete;
|
||||
bool _header_is_complete;
|
||||
bool _header_is_valid;
|
||||
char *_start;
|
||||
char *_next_in;
|
||||
int _bytes_in_buffer;
|
||||
int _total_bytes_written;
|
||||
int _total_bytes_requested;
|
||||
int _first_byte;
|
||||
int _last_byte;
|
||||
int _total_bytes;
|
||||
bool _partial_content;
|
||||
char *_buffer;
|
||||
};
|
||||
|
||||
INLINE void recompute_buffer(void);
|
||||
|
||||
int connect_to_server(void);
|
||||
int safe_send(int socket, const char *data, int length, long timeout);
|
||||
int fast_receive(int socket, DownloadStatus *status, int rec_size);
|
||||
int parse_http_response(const string &resp);
|
||||
int parse_header(DownloadStatus *status);
|
||||
int write_to_disk(DownloadStatus *status);
|
||||
int run_to_ram(void);
|
||||
int write_to_ram(DownloadStatus *status);
|
||||
|
||||
private:
|
||||
bool _connected;
|
||||
int _socket;
|
||||
string _server_name;
|
||||
bool _use_proxy;
|
||||
string _proxy_string;
|
||||
struct sockaddr_in _sin;
|
||||
bool _TCP_stack_initialized;
|
||||
|
||||
bool _initiated;
|
||||
bool _ever_initiated;
|
||||
PT(Buffer) _buffer;
|
||||
int _disk_write_frequency;
|
||||
float _frequency;
|
||||
float _byte_rate;
|
||||
ulong _receive_size;
|
||||
int _disk_buffer_size;
|
||||
ofstream _dest_stream;
|
||||
ostringstream *_dest_string_stream;
|
||||
bool _recompute_buffer;
|
||||
|
||||
DownloadStatus *_current_status;
|
||||
bool _got_any_data;
|
||||
int _total_bytes_written;
|
||||
int _total_bytes_requested;
|
||||
bool _download_to_ram;
|
||||
|
||||
int _file_size;
|
||||
|
||||
double _tlast;
|
||||
double _tfirst;
|
||||
ClockObject _clock;
|
||||
};
|
||||
|
||||
#include "downloader.I"
|
||||
|
||||
#endif
|
||||
|
|
@ -1,3 +1,2 @@
|
|||
#include "downloader.cxx"
|
||||
#include "downloadDb.cxx"
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue