Fixed 'Debugger stalls at HttpWebRequest.BeginGetResponse()' in maptester scene, when you click map request button

This commit is contained in:
alexiscatnip
2021-08-10 23:36:17 +08:00
parent a9dc413f95
commit fd679ec9b9
4 changed files with 91 additions and 23 deletions
@@ -30,6 +30,7 @@ using System.Net;
using System.IO;
using System.Threading;
using System.Security.Cryptography.X509Certificates;
using UnityEngine;
namespace OpenMetaverse.Http
{
@@ -107,6 +108,8 @@ namespace OpenMetaverse.Http
// Start the request for the remote server response
IAsyncResult result = request.BeginGetResponse(GetResponse, state);
Debug.Log("testing");
// Register a timeout for the request
ThreadPool.RegisterWaitForSingleObject(result.AsyncWaitHandle, TimeoutCallback, state, millisecondsTimeout, true);
}
+45 -9
View File
@@ -80,7 +80,7 @@ namespace Raindrop
downloader.QueueDownlad(
new Uri(string.Format("http://map.secondlife.com/map-{0}-{1}-{2}-objects.jpg", zoom, regX, regY)),
20 * 1000,
3 * 1000, // was 20.
null,
null,
(request, response, responseData, error) =>
@@ -89,16 +89,17 @@ namespace Raindrop
{
try
{
Debug.Log("done!");
//using (MemoryStream s = new MemoryStream(responseData)) //s of JPEG
//{
//lock (mapData.regionTiles)
//{
// //decode http response data into texture2d
// MapTile tex = mapData.getUnusedTex();
// tex.texture.LoadImage(responseData); //Image.FromStream(s);
// //mapData.regionTiles[handle] =
// //needRepaint = true;
//}
//lock (mapData.regionTiles)
//{
// //decode http response data into texture2d
// MapTile tex = mapData.getUnusedTex();
// tex.texture.LoadImage(responseData); //Image.FromStream(s);
// //mapData.regionTiles[handle] =
// //needRepaint = true;
//}
//}
}
catch { }
@@ -106,6 +107,41 @@ namespace Raindrop
}
);
//downloader.QueueDownlad(
// new Uri(string.Format("http://map.secondlife.com/map-{0}-{1}-{2}-objects.jpg", zoom, regX, regY)),
// 3 * 1000, // was 20.
// null,
// null,
// (request, response, responseData, error) =>
// {
// if (error == null && responseData != null)
// {
// try
// {
// Debug.Log("done!");
// //using (MemoryStream s = new MemoryStream(responseData)) //s of JPEG
// //{
// //lock (mapData.regionTiles)
// //{
// // //decode http response data into texture2d
// // MapTile tex = mapData.getUnusedTex();
// // tex.texture.LoadImage(responseData); //Image.FromStream(s);
// // //mapData.regionTiles[handle] =
// // //needRepaint = true;
// //}
// //}
// }
// catch { }
// }
// }
//);
lock (mapData.regionTiles)
{
mapData.regionTiles[handle] = null;
+31 -12
View File
@@ -72,22 +72,41 @@ namespace Raindrop.Network
for (int i = nr; i < ParallelDownloads && queue.Count > 0; i++)
{
QueuedItem item = queue.Dequeue();
Debug.Log("Requesting " + item.address);
HttpWebRequest req = SetupRequest(item.address, item.contentType);
CapsBase.DownloadDataAsync(
req,
QueuedItem item = queue.Dequeue(); //checlk this
var req = CapsBase.DownloadStringAsync(
item.address,
null,
item.millisecondsTimeout,
item.downloadProgressCallback,
(request, response, responseData, error) =>
{
lock (activeDownloads) activeDownloads.Remove(request);
item.completedCallback(request, response, responseData, error);
EnqueuePending();
}
);
{
lock (activeDownloads) activeDownloads.Remove(request);
item.completedCallback(request, response, responseData, error);
EnqueuePending();
Debug.Log("CompletionCallback done!.");
}
);
lock (activeDownloads) activeDownloads.Add(req);
//Why the fuck the following snippet, which was the original implementaion in radegast, causes the main thread to stall on the instruction
// " IAsyncResult result = request.BeginGetResponse(GetResponse, state); " in CapsBase.cs line 110 (call to DownloadDataAsync() ).
// like really why???
//Debug.Log("Requesting " + item.address);
//HttpWebRequest req = SetupRequest(item.address, item.contentType);
//CapsBase.DownloadDataAsync(
// req,
// item.millisecondsTimeout,
// item.downloadProgressCallback,
// (request, response, responseData, error) =>
// {
// lock (activeDownloads) activeDownloads.Remove(request);
// item.completedCallback(request, response, responseData, error);
// EnqueuePending();
// }
//);
lock (activeDownloads) activeDownloads.Add(req); // this line?
}
}
}
@@ -25,11 +25,21 @@ namespace Raindrop
{
//HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.google.com");
//request.BeginGetResponse(new AsyncCallback(Finish), request);;
//HttpWebRequest request = (HttpWebRequest)WebRequest.Create(string.Format("http://map.secondlife.com/map-1-1000-1000-objects.jpg"));
//request.Timeout = 3 * 1000;
//request.BeginGetResponse(new AsyncCallback(Finish), request); ;
// Create an object to hold all of the state for this request
//IAsyncResult result = request.BeginGetResponse(Finish, request);
//ServicePointManager.ServerCertificateValidationCallback =
// (sender, certificate, chain, sslPolicyErrors) => true;
var handle = Utils.UIntsToLong(256 * 1000, 256 * 1000);
mapFetcher.GetRegionTileExternal(handle, 1);
Debug.Log("end of start fetch subroutine");
}