From b714801f415860179198776043c5078530d5f804 Mon Sep 17 00:00:00 2001 From: gareth Date: Wed, 28 Feb 2007 19:47:05 +0000 Subject: [PATCH] Assets? --- src/OpenSimClient.cs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/OpenSimClient.cs b/src/OpenSimClient.cs index b430c3e231..f9349db2c0 100644 --- a/src/OpenSimClient.cs +++ b/src/OpenSimClient.cs @@ -51,6 +51,7 @@ namespace OpenSim private Thread ClientThread; private EndPoint userEP; private BlockingQueue PacketQueue; + private BlockingQueue AssetRequests; private Dictionary PendingAcks = new Dictionary(); private Dictionary NeedAck = new Dictionary(); private System.Timers.Timer AckTimer; @@ -77,6 +78,28 @@ namespace OpenSim } } + public void AssetLoader() { + Console.WriteLine("OpenSimClient.cs:AssetLoader() - Starting new thread"); + TransferRequestPacket reqPacket = AssetRequests.Dequeue(); + Console.WriteLine("OpenSimClient.cs:AssetLoader() - Got a request, processing it"); + LLUUID AssetID = new LLUUID(reqPacket.TransferInfo.Params, 0); + WebRequest AssetLoad = WebRequest.Create(OpenSim_Main.cfg.AssetURL + "getasset/" + OpenSim_Main.cfg.AssetSendKey + "/" + AssetID + "/data"); + WebResponse AssetResponse = AssetLoad.GetResponse(); + byte[] idata = new byte[(int)AssetResponse.ContentLength]; + BinaryReader br = new BinaryReader(AssetResponse.GetResponseStream()); + idata = br.ReadBytes((int)AssetResponse.ContentLength); + br.Close(); + AssetResponse.Close(); + + TransferInfoPacket Transfer = new TransferInfoPacket(); + Transfer.TransferInfo.ChannelType = 2; + Transfer.TransferInfo.Status = 0; + Transfer.TransferInfo.TargetType = 0; + Transfer.TransferInfo.Params = reqPacket.TransferInfo.Params; + Transfer.TransferInfo.Size = (int)AssetResponse.ContentLength; + Transfer.TransferInfo.TransferID = reqPacket.TransferInfo.TransferID; + } + public void ProcessInPacket(Packet Pack) { ack_pack(Pack); switch(Pack.Type) { @@ -86,6 +109,14 @@ namespace OpenSim case PacketType.RegionHandshakeReply: OpenSim_Main.local_world.SendLayerData(this); break; + case PacketType.TransferRequest: + // We put transfer requests into a big queue and then spawn a thread for each new one + TransferRequestPacket transfer = (TransferRequestPacket)Pack; + AssetRequests.Enqueue(transfer); + Thread AssetLoaderThread = new Thread(new ThreadStart(AssetLoader)); + AssetLoaderThread.IsBackground = true; + AssetLoaderThread.Start(); + break; } } @@ -284,6 +315,7 @@ namespace OpenSim cirpack = initialcirpack; userEP = remoteEP; PacketQueue = new BlockingQueue(); + AssetRequests = new BlockingQueue(); AckTimer = new System.Timers.Timer(500); AckTimer.Elapsed += new ElapsedEventHandler(AckTimer_Elapsed); AckTimer.Start();