Update the example program so it handles meshes as well. Fix the

Wed, 03 Jul 2013 15:17:26 -0400

author
Monty Brandenberg <monty@lindenlab.com>
date
Wed, 03 Jul 2013 15:17:26 -0400
changeset 40691
0dc3766d2ff3
parent 40689
db8a294b2cab
child 40692
c7519f1e63cf

Update the example program so it handles meshes as well. Fix the
request feed logic to use high/low-water level logic as is done
in viewer code.

indra/llcorehttp/examples/http_texture_load.cpp file | annotate | diff | revisions
     1.1 --- a/indra/llcorehttp/examples/http_texture_load.cpp	Fri Jun 28 20:08:29 2013 -0400
     1.2 +++ b/indra/llcorehttp/examples/http_texture_load.cpp	Wed Jul 03 15:17:26 2013 -0400
     1.3 @@ -39,6 +39,7 @@
     1.4  #include "httprequest.h"
     1.5  #include "httphandler.h"
     1.6  #include "httpresponse.h"
     1.7 +#include "httpoptions.h"
     1.8  #include "httpheaders.h"
     1.9  #include "bufferarray.h"
    1.10  #include "_mutex.h"
    1.11 @@ -79,11 +80,11 @@
    1.12  	WorkingSet();
    1.13  	~WorkingSet();
    1.14  
    1.15 -	bool reload(LLCore::HttpRequest *);
    1.16 +	bool reload(LLCore::HttpRequest *, LLCore::HttpOptions *);
    1.17  	
    1.18  	virtual void onCompleted(LLCore::HttpHandle handle, LLCore::HttpResponse * response);
    1.19  
    1.20 -	void loadTextureUuids(FILE * in);
    1.21 +	void loadAssetUuids(FILE * in);
    1.22  	
    1.23  public:
    1.24  	struct Spec
    1.25 @@ -93,18 +94,19 @@
    1.26  		int				mLength;
    1.27  	};
    1.28  	typedef std::set<LLCore::HttpHandle> handle_set_t;
    1.29 -	typedef std::vector<Spec> texture_list_t;
    1.30 +	typedef std::vector<Spec> asset_list_t;
    1.31  	
    1.32  public:
    1.33  	bool						mVerbose;
    1.34  	bool						mRandomRange;
    1.35 -	int							mMaxConcurrency;
    1.36 +	int							mRequestLowWater;
    1.37 +	int							mRequestHighWater;
    1.38  	handle_set_t				mHandles;
    1.39  	int							mRemaining;
    1.40  	int							mLimit;
    1.41  	int							mAt;
    1.42  	std::string					mUrl;
    1.43 -	texture_list_t				mTextures;
    1.44 +	asset_list_t				mAssets;
    1.45  	int							mErrorsApi;
    1.46  	int							mErrorsHttp;
    1.47  	int							mErrorsHttp404;
    1.48 @@ -224,17 +226,23 @@
    1.49  	// Get service point
    1.50  	LLCore::HttpRequest * hr = new LLCore::HttpRequest();
    1.51  
    1.52 +	// Get request options
    1.53 +	LLCore::HttpOptions * opt = new LLCore::HttpOptions();
    1.54 +	opt->setRetries(12);
    1.55 +	opt->setUseRetryAfter(true);
    1.56 +	
    1.57  	// Get a handler/working set
    1.58  	WorkingSet ws;
    1.59  
    1.60  	// Fill the working set with work
    1.61  	ws.mUrl = url_format;
    1.62 -	ws.loadTextureUuids(uuids);
    1.63 +	ws.loadAssetUuids(uuids);
    1.64  	ws.mRandomRange = do_random;
    1.65  	ws.mVerbose = do_verbose;
    1.66 -	ws.mMaxConcurrency = 100;
    1.67 +	ws.mRequestHighWater = 100;
    1.68 +	ws.mRequestLowWater = ws.mRequestHighWater / 2;
    1.69  	
    1.70 -	if (! ws.mTextures.size())
    1.71 +	if (! ws.mAssets.size())
    1.72  	{
    1.73  		std::cerr << "No UUIDs found in file '" << argv[optind] << "'." << std::endl;
    1.74  		return 1;
    1.75 @@ -246,9 +254,9 @@
    1.76  	
    1.77  	// Run it
    1.78  	int passes(0);
    1.79 -	while (! ws.reload(hr))
    1.80 +	while (! ws.reload(hr, opt))
    1.81  	{
    1.82 -		hr->update(5000000);
    1.83 +		hr->update(0);
    1.84  		ms_sleep(2);
    1.85  		if (0 == (++passes % 200))
    1.86  		{
    1.87 @@ -275,6 +283,8 @@
    1.88  	// Clean up
    1.89  	hr->requestStopThread(NULL);
    1.90  	ms_sleep(1000);
    1.91 +	opt->release();
    1.92 +	opt = NULL;
    1.93  	delete hr;
    1.94  	LLCore::HttpRequest::destroyService();
    1.95  	term_curl();
    1.96 @@ -325,7 +335,7 @@
    1.97  	  mSuccesses(0),
    1.98  	  mByteCount(0L)
    1.99  {
   1.100 -	mTextures.reserve(30000);
   1.101 +	mAssets.reserve(30000);
   1.102  
   1.103  	mHeaders = new LLCore::HttpHeaders;
   1.104  	mHeaders->append("Accept", "image/x-j2c");
   1.105 @@ -342,29 +352,35 @@
   1.106  }
   1.107  
   1.108  
   1.109 -bool WorkingSet::reload(LLCore::HttpRequest * hr)
   1.110 +bool WorkingSet::reload(LLCore::HttpRequest * hr, LLCore::HttpOptions * opt)
   1.111  {
   1.112 -	int to_do((std::min)(mRemaining, mMaxConcurrency - int(mHandles.size())));
   1.113 +	if (mRequestLowWater <= mHandles.size())
   1.114 +	{
   1.115 +		// Haven't fallen below low-water level yet.
   1.116 +		return false;
   1.117 +	}
   1.118 +	
   1.119 +	int to_do((std::min)(mRemaining, mRequestHighWater - int(mHandles.size())));
   1.120  
   1.121  	for (int i(0); i < to_do; ++i)
   1.122  	{
   1.123  		char buffer[1024];
   1.124  #if	defined(WIN32)
   1.125 -		_snprintf_s(buffer, sizeof(buffer), sizeof(buffer) - 1, mUrl.c_str(), mTextures[mAt].mUuid.c_str());
   1.126 +		_snprintf_s(buffer, sizeof(buffer), sizeof(buffer) - 1, mUrl.c_str(), mAssets[mAt].mUuid.c_str());
   1.127  #else
   1.128 -		snprintf(buffer, sizeof(buffer), mUrl.c_str(), mTextures[mAt].mUuid.c_str());
   1.129 +		snprintf(buffer, sizeof(buffer), mUrl.c_str(), mAssets[mAt].mUuid.c_str());
   1.130  #endif
   1.131 -		int offset(mRandomRange ? ((unsigned long) rand()) % 1000000UL : mTextures[mAt].mOffset);
   1.132 -		int length(mRandomRange ? ((unsigned long) rand()) % 1000000UL : mTextures[mAt].mLength);
   1.133 +		int offset(mRandomRange ? ((unsigned long) rand()) % 1000000UL : mAssets[mAt].mOffset);
   1.134 +		int length(mRandomRange ? ((unsigned long) rand()) % 1000000UL : mAssets[mAt].mLength);
   1.135  
   1.136  		LLCore::HttpHandle handle;
   1.137  		if (offset || length)
   1.138  		{
   1.139 -			handle = hr->requestGetByteRange(0, 0, buffer, offset, length, NULL, mHeaders, this);
   1.140 +			handle = hr->requestGetByteRange(0, 0, buffer, offset, length, opt, mHeaders, this);
   1.141  		}
   1.142  		else
   1.143  		{
   1.144 -			handle = hr->requestGet(0, 0, buffer, NULL, mHeaders, this);
   1.145 +			handle = hr->requestGet(0, 0, buffer, opt, mHeaders, this);
   1.146  		}
   1.147  		if (! handle)
   1.148  		{
   1.149 @@ -459,21 +475,21 @@
   1.150  }
   1.151  
   1.152  
   1.153 -void WorkingSet::loadTextureUuids(FILE * in)
   1.154 +void WorkingSet::loadAssetUuids(FILE * in)
   1.155  {
   1.156  	char buffer[1024];
   1.157  
   1.158  	while (fgets(buffer, sizeof(buffer), in))
   1.159  	{
   1.160 -		WorkingSet::Spec texture;
   1.161 +		WorkingSet::Spec asset;
   1.162  		char * state(NULL);
   1.163  		char * token = strtok_r(buffer, " \t\n,", &state);
   1.164  		if (token && 36 == strlen(token))
   1.165  		{
   1.166  			// Close enough for this function
   1.167 -			texture.mUuid = token;
   1.168 -			texture.mOffset = 0;
   1.169 -			texture.mLength = 0;
   1.170 +			asset.mUuid = token;
   1.171 +			asset.mOffset = 0;
   1.172 +			asset.mLength = 0;
   1.173  			token = strtok_r(buffer, " \t\n,", &state);
   1.174  			if (token)
   1.175  			{
   1.176 @@ -482,14 +498,14 @@
   1.177  				if (token)
   1.178  				{
   1.179  					int length(atoi(token));
   1.180 -					texture.mOffset = offset;
   1.181 -					texture.mLength = length;
   1.182 +					asset.mOffset = offset;
   1.183 +					asset.mLength = length;
   1.184  				}
   1.185  			}
   1.186 -			mTextures.push_back(texture);
   1.187 +			mAssets.push_back(asset);
   1.188  		}
   1.189  	}
   1.190 -	mRemaining = mLimit = mTextures.size();
   1.191 +	mRemaining = mLimit = mAssets.size();
   1.192  }
   1.193  
   1.194  

mercurial