private static void DataCallback(int reqId, IntPtr data, int size) { //may be called on any thread WebResources.Response response; lock (requests) { if (!requests.TryGetValue(reqId, out response)) { response = new WebResources.Response() { data = Encoding.UTF8.GetBytes("No response for request!"), mimeType = "text/plain", responseCode = 500, }; } requests.Remove(reqId); } Assert.AreEqual(response.data.Length, size); if (size != 0) { Marshal.Copy(response.data, 0, data, size); } }
private static int HeaderCallback(string url, IntPtr mimeTypeDest, out int size, out int responseCode) { //may be called on any thread //Chop up the URL so it's easy to digest. if (url.SafeStartsWith(LocalUrlPrefix)) { url = "/" + url.Substring(LocalUrlPrefix.Length); } WebResources.Response response; if (webResources == null) { response = new WebResources.Response() { data = Encoding.UTF8.GetBytes("No WebResources handler!"), mimeType = "text/plain", responseCode = 500, }; } else { response = webResources[url]; } var data = Encoding.UTF8.GetBytes(response.mimeType); if (data.Length > 99) { Debug.LogWarning("mime type is too long " + response.mimeType); data = new byte[0]; } Marshal.Copy(data, 0, mimeTypeDest, data.Length); Marshal.WriteByte(mimeTypeDest, data.Length, 0); //null-terminate responseCode = response.responseCode; size = response.data.Length; int id; lock (requests) { id = nextRequestId++; requests[id] = response; } return(id); }
private static void DataCallback(int reqId, IntPtr data, int size) { WebResources.Response value; lock (requests) { if (!requests.TryGetValue(reqId, out value)) { WebResources.Response response = default(WebResources.Response); response.data = Encoding.UTF8.GetBytes("No response for request!"); response.mimeType = "text/plain"; response.responseCode = 500; value = response; } requests.Remove(reqId); } Assert.AreEqual(value.data.Length, size); if (size != 0) { Marshal.Copy(value.data, 0, data, size); } }
private static int HeaderCallback(string url, IntPtr mimeTypeDest, out int size, out int responseCode) { if (url.SafeStartsWith(LocalUrlPrefix)) { url = "/" + url.Substring(LocalUrlPrefix.Length); } WebResources.Response value; if (webResources == null) { WebResources.Response response = default(WebResources.Response); response.data = Encoding.UTF8.GetBytes("No WebResources handler!"); response.mimeType = "text/plain"; response.responseCode = 500; value = response; } else { value = webResources[url]; } byte[] array = Encoding.UTF8.GetBytes(value.mimeType); if (array.Length > 99) { Debug.LogWarning("mime type is too long " + value.mimeType); array = new byte[0]; } Marshal.Copy(array, 0, mimeTypeDest, array.Length); Marshal.WriteByte(mimeTypeDest, array.Length, 0); responseCode = value.responseCode; size = value.data.Length; int num; lock (requests) { num = nextRequestId++; requests[num] = value; } return(num); }