simplify GruntWork on getassets (needs more)
parent
48892ad8a7
commit
baf5c61387
|
@ -28,10 +28,8 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Specialized;
|
using System.Net;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.IO;
|
|
||||||
using System.Web;
|
|
||||||
using log4net;
|
using log4net;
|
||||||
using Nini.Config;
|
using Nini.Config;
|
||||||
using OpenMetaverse;
|
using OpenMetaverse;
|
||||||
|
@ -79,25 +77,22 @@ namespace OpenSim.Capabilities.Handlers
|
||||||
m_assetService = assService;
|
m_assetService = assService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Hashtable Handle(OSHttpRequest req)
|
public void Handle(OSHttpRequest req, OSHttpResponse response)
|
||||||
{
|
{
|
||||||
Hashtable responsedata = new Hashtable();
|
response.ContentType = "text/plain";
|
||||||
responsedata["content_type"] = "text/plain";
|
|
||||||
responsedata["int_bytes"] = 0;
|
|
||||||
|
|
||||||
if (m_assetService == null)
|
if (m_assetService == null)
|
||||||
{
|
{
|
||||||
responsedata["int_response_code"] = (int)System.Net.HttpStatusCode.ServiceUnavailable;
|
response.StatusCode = (int)HttpStatusCode.ServiceUnavailable;
|
||||||
responsedata["str_response_string"] = "The asset service is unavailable";
|
response.KeepAlive = false;
|
||||||
responsedata["keepalive"] = false;
|
return;
|
||||||
return responsedata;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
responsedata["int_response_code"] = (int)System.Net.HttpStatusCode.BadRequest;
|
response.StatusCode = (int)HttpStatusCode.BadRequest;
|
||||||
|
|
||||||
var queries = req.QueryAsDictionary;
|
var queries = req.QueryAsDictionary;
|
||||||
if(queries.Count == 0)
|
if(queries.Count == 0)
|
||||||
return responsedata;
|
return;
|
||||||
|
|
||||||
AssetType type = AssetType.Unknown;
|
AssetType type = AssetType.Unknown;
|
||||||
string assetStr = string.Empty;
|
string assetStr = string.Empty;
|
||||||
|
@ -115,30 +110,27 @@ namespace OpenSim.Capabilities.Handlers
|
||||||
{
|
{
|
||||||
//m_log.Warn("[GETASSET]: Unknown type: " + query);
|
//m_log.Warn("[GETASSET]: Unknown type: " + query);
|
||||||
m_log.Warn("[GETASSET]: Unknown type");
|
m_log.Warn("[GETASSET]: Unknown type");
|
||||||
return responsedata;
|
response.StatusCode = (int)HttpStatusCode.NotFound;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (String.IsNullOrEmpty(assetStr))
|
if (String.IsNullOrEmpty(assetStr))
|
||||||
return responsedata;
|
return;
|
||||||
|
|
||||||
UUID assetID = UUID.Zero;
|
UUID assetID = UUID.Zero;
|
||||||
if(!UUID.TryParse(assetStr, out assetID))
|
if(!UUID.TryParse(assetStr, out assetID))
|
||||||
return responsedata;
|
return;
|
||||||
|
|
||||||
AssetBase asset = m_assetService.Get(assetID.ToString());
|
AssetBase asset = m_assetService.Get(assetID.ToString());
|
||||||
if(asset == null)
|
if(asset == null)
|
||||||
{
|
{
|
||||||
// m_log.Warn("[GETASSET]: not found: " + query + " " + assetStr);
|
// m_log.Warn("[GETASSET]: not found: " + query + " " + assetStr);
|
||||||
responsedata["int_response_code"] = (int)System.Net.HttpStatusCode.NotFound;
|
response.StatusCode = (int)HttpStatusCode.NotFound;
|
||||||
responsedata["str_response_string"] = "Asset not found.";
|
return;
|
||||||
return responsedata;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (asset.Type != (sbyte)type)
|
if (asset.Type != (sbyte)type)
|
||||||
{
|
return;
|
||||||
responsedata["str_response_string"] = "Got wrong asset type";
|
|
||||||
return responsedata;
|
|
||||||
}
|
|
||||||
|
|
||||||
int len = asset.Data.Length;
|
int len = asset.Data.Length;
|
||||||
|
|
||||||
|
@ -156,8 +148,8 @@ namespace OpenSim.Capabilities.Handlers
|
||||||
// sending back the last byte instead of an error status
|
// sending back the last byte instead of an error status
|
||||||
if (start >= asset.Data.Length)
|
if (start >= asset.Data.Length)
|
||||||
{
|
{
|
||||||
responsedata["str_response_string"] = "This range doesnt exist.";
|
response.StatusCode = (int)HttpStatusCode.RequestedRangeNotSatisfiable;
|
||||||
return responsedata;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (end == -1)
|
if (end == -1)
|
||||||
|
@ -169,32 +161,30 @@ namespace OpenSim.Capabilities.Handlers
|
||||||
len = end - start + 1;
|
len = end - start + 1;
|
||||||
|
|
||||||
//m_log.Debug("Serving " + start + " to " + end + " of " + texture.Data.Length + " bytes for texture " + texture.ID);
|
//m_log.Debug("Serving " + start + " to " + end + " of " + texture.Data.Length + " bytes for texture " + texture.ID);
|
||||||
Hashtable headers = new Hashtable();
|
response.AddHeader("Content-Range", String.Format("bytes {0}-{1}/{2}", start, end, asset.Data.Length));
|
||||||
headers["Content-Range"] = String.Format("bytes {0}-{1}/{2}", start, end, asset.Data.Length);
|
response.StatusCode = (int)HttpStatusCode.PartialContent;
|
||||||
responsedata["headers"] = headers;
|
response.RawBufferStart = start;
|
||||||
responsedata["int_response_code"] = (int)System.Net.HttpStatusCode.PartialContent;
|
|
||||||
responsedata["bin_start"] = start;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
responsedata["int_response_code"] = (int)System.Net.HttpStatusCode.OK;
|
response.StatusCode = (int)HttpStatusCode.OK;
|
||||||
|
|
||||||
responsedata["content_type"] = asset.Metadata.ContentType;
|
response.ContentType = asset.Metadata.ContentType;
|
||||||
responsedata["bin_response_data"] = asset.Data;
|
response.RawBuffer = asset.Data;
|
||||||
responsedata["int_bytes"] = len;
|
response.RawBufferLen = len;
|
||||||
if (type == AssetType.Mesh || type == AssetType.Texture)
|
if (type == AssetType.Mesh || type == AssetType.Texture)
|
||||||
{
|
{
|
||||||
if(len > 8196)
|
if(len > 8196)
|
||||||
{
|
{
|
||||||
responsedata["throttle"] = true;
|
|
||||||
//if(type == AssetType.Texture && ((asset.Flags & AssetFlags.AvatarBake)!= 0))
|
//if(type == AssetType.Texture && ((asset.Flags & AssetFlags.AvatarBake)!= 0))
|
||||||
// responsedata["prio"] = 1;
|
// responsedata["prio"] = 1;
|
||||||
//else
|
//else
|
||||||
responsedata["prio"] = 2;
|
response.Priority = 2;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
responsedata["prio"] = 1;
|
response.Priority = 1;
|
||||||
}
|
}
|
||||||
return responsedata; // full asset
|
else
|
||||||
|
response.Priority = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -46,8 +46,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||||
public readonly int RequestTime;
|
public readonly int RequestTime;
|
||||||
public readonly UUID RequestID;
|
public readonly UUID RequestID;
|
||||||
|
|
||||||
public PollServiceHttpRequest(
|
public PollServiceHttpRequest(PollServiceEventArgs pPollServiceArgs, IHttpRequest pRequest)
|
||||||
PollServiceEventArgs pPollServiceArgs, IHttpRequest pRequest)
|
|
||||||
{
|
{
|
||||||
PollServiceArgs = pPollServiceArgs;
|
PollServiceArgs = pPollServiceArgs;
|
||||||
Request = pRequest;
|
Request = pRequest;
|
||||||
|
@ -60,6 +59,18 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||||
if (Request.Body.CanRead)
|
if (Request.Body.CanRead)
|
||||||
Request.Body.Dispose();
|
Request.Body.Dispose();
|
||||||
|
|
||||||
|
if(responsedata.Contains("h"))
|
||||||
|
{
|
||||||
|
OSHttpResponse r = (OSHttpResponse)responsedata["h"];
|
||||||
|
try
|
||||||
|
{
|
||||||
|
r.Send();
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
PollServiceArgs.RequestsHandled++;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
OSHttpResponse response = new OSHttpResponse(new HttpResponse(Request));
|
OSHttpResponse response = new OSHttpResponse(new HttpResponse(Request));
|
||||||
|
|
||||||
if (responsedata == null)
|
if (responsedata == null)
|
||||||
|
@ -105,7 +116,6 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
response.StatusCode = responsecode;
|
response.StatusCode = responsecode;
|
||||||
if (responsecode == (int)HttpStatusCode.Moved)
|
if (responsecode == (int)HttpStatusCode.Moved)
|
||||||
{
|
{
|
||||||
|
|
|
@ -65,15 +65,12 @@ namespace OpenSim.Region.ClientStack.Linden
|
||||||
{
|
{
|
||||||
public PollServiceAssetEventArgs thepoll;
|
public PollServiceAssetEventArgs thepoll;
|
||||||
public UUID reqID;
|
public UUID reqID;
|
||||||
//public Hashtable request;
|
|
||||||
public OSHttpRequest request;
|
public OSHttpRequest request;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class APollResponse
|
public class APollResponse
|
||||||
{
|
{
|
||||||
public Hashtable response;
|
public OSHttpResponse osresponse;
|
||||||
public int bytes;
|
|
||||||
public bool throttle;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
|
@ -241,7 +238,6 @@ namespace OpenSim.Region.ClientStack.Linden
|
||||||
{
|
{
|
||||||
m_scene = scene;
|
m_scene = scene;
|
||||||
|
|
||||||
|
|
||||||
HasEvents = (requestID, agentID) =>
|
HasEvents = (requestID, agentID) =>
|
||||||
{
|
{
|
||||||
lock (responses)
|
lock (responses)
|
||||||
|
@ -254,9 +250,15 @@ namespace OpenSim.Region.ClientStack.Linden
|
||||||
|
|
||||||
if (m_presence == null || m_presence.IsDeleted)
|
if (m_presence == null || m_presence.IsDeleted)
|
||||||
return true;
|
return true;
|
||||||
if(response.throttle)
|
|
||||||
return m_presence.CapCanSendAsset(1, response.bytes);
|
OSHttpResponse resp = response.osresponse;
|
||||||
return m_presence.CapCanSendAsset(2, response.bytes);
|
|
||||||
|
if(Util.GetTimeStamp() - resp.RequestTS > (resp.RawBufferLen > 2000000 ? 200 : 90))
|
||||||
|
return m_presence.CapCanSendAsset(2, resp.RawBufferLen);
|
||||||
|
|
||||||
|
if (resp.Priority > 1)
|
||||||
|
return m_presence.CapCanSendAsset(1, resp.RawBufferLen);
|
||||||
|
return m_presence.CapCanSendAsset(2, resp.RawBufferLen);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -278,7 +280,13 @@ namespace OpenSim.Region.ClientStack.Linden
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return responses[requestID].response;
|
OSHttpResponse response = responses[requestID].osresponse;
|
||||||
|
if (response.Priority < 0)
|
||||||
|
response.Priority = 0;
|
||||||
|
|
||||||
|
Hashtable lixo = new Hashtable(1);
|
||||||
|
lixo["h"] = response;
|
||||||
|
return lixo;
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
@ -319,8 +327,6 @@ namespace OpenSim.Region.ClientStack.Linden
|
||||||
|
|
||||||
public void Process(APollRequest requestinfo)
|
public void Process(APollRequest requestinfo)
|
||||||
{
|
{
|
||||||
Hashtable curresponse;
|
|
||||||
|
|
||||||
UUID requestID = requestinfo.reqID;
|
UUID requestID = requestinfo.reqID;
|
||||||
|
|
||||||
if(m_scene.ShuttingDown)
|
if(m_scene.ShuttingDown)
|
||||||
|
@ -350,8 +356,8 @@ namespace OpenSim.Region.ClientStack.Linden
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
OSHttpResponse response = new OSHttpResponse(requestinfo.request);
|
||||||
curresponse = m_getAssetHandler.Handle(requestinfo.request);
|
m_getAssetHandler.Handle(requestinfo.request, response);
|
||||||
|
|
||||||
lock(responses)
|
lock(responses)
|
||||||
{
|
{
|
||||||
|
@ -366,11 +372,8 @@ namespace OpenSim.Region.ClientStack.Linden
|
||||||
|
|
||||||
APollResponse preq= new APollResponse()
|
APollResponse preq= new APollResponse()
|
||||||
{
|
{
|
||||||
bytes = (int)curresponse["int_bytes"],
|
osresponse = response
|
||||||
response = curresponse
|
|
||||||
};
|
};
|
||||||
if(curresponse.Contains("throttle"))
|
|
||||||
preq.throttle = true;
|
|
||||||
responses[requestID] = preq;
|
responses[requestID] = preq;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue