AxiHttp规范

This commit is contained in:
sin365 2025-08-21 10:32:38 +08:00
parent dd12a88d11
commit ccf2279947
6 changed files with 181 additions and 110 deletions

View File

@ -1,79 +1,79 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO.Compression; using System.IO.Compression;
using System.Net; using System.Net;
using System.Net.Security; using System.Net.Security;
using System.Net.Sockets; using System.Net.Sockets;
using System.Security.Authentication; using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.X509Certificates;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading; using System.Threading;
public static class PSVThread public static class PSVThread
{ {
#if UNITY_PSP2 #if UNITY_PSP2
static AutoResetEvent autoEvent = new AutoResetEvent(false); static AutoResetEvent autoEvent = new AutoResetEvent(false);
static Queue<Action> qActs = new Queue<Action>(); static Queue<Action> qActs = new Queue<Action>();
static Queue<Action> qWork = new Queue<Action>(); static Queue<Action> qWork = new Queue<Action>();
#endif #endif
public static void DoTask(Action act) public static void DoTask(Action act)
{ {
#if UNITY_PSP2 #if UNITY_PSP2
AddSingleTask(act); AddSingleTask(act);
#else #else
ThreadPool.QueueUserWorkItem(new WaitCallback((state) => act.Invoke())); ThreadPool.QueueUserWorkItem(new WaitCallback((state) => act.Invoke()));
#endif #endif
} }
#if UNITY_PSP2 #if UNITY_PSP2
static Thread psvThread = new Thread(Loop); static Thread psvThread = new Thread(Loop);
static bool bSingleInit = false; static bool bSingleInit = false;
static void SingleInit() static void SingleInit()
{ {
if (bSingleInit) return; if (bSingleInit) return;
psvThread.Start(); psvThread.Start();
bSingleInit = true; bSingleInit = true;
} }
static void AddSingleTask(Action act) static void AddSingleTask(Action act)
{ {
SingleInit(); SingleInit();
lock (qActs) lock (qActs)
{ {
qActs.Enqueue(act); qActs.Enqueue(act);
} }
autoEvent.Set(); autoEvent.Set();
} }
static void Loop() static void Loop()
{ {
while (autoEvent.WaitOne()) while (autoEvent.WaitOne())
{ {
lock (qActs) lock (qActs)
{ {
while (qActs.Count > 0) { qWork.Enqueue(qActs.Dequeue()); } while (qActs.Count > 0) { qWork.Enqueue(qActs.Dequeue()); }
} }
while (qWork.Count > 0) while (qWork.Count > 0)
{ {
Action act = qWork.Dequeue(); Action act = qWork.Dequeue();
try try
{ {
act.Invoke(); act.Invoke();
} }
catch (Exception ex) catch (Exception ex)
{ {
UnityEngine.Debug.Log(ex.ToString()); UnityEngine.Debug.Log(ex.ToString());
} }
} }
} }
} }
#endif #endif
} }
public static class AxiHttp public static class AxiHttp
{ {
public const char T = '\n'; public const char T = '\n';
public const string CT = "\r\n"; public const string CT = "\r\n";
@ -1016,10 +1016,10 @@ public static class AxiHttp
string strRelativePathRet; string strRelativePathRet;
string strIPRet; string strIPRet;
/*string strProtocol = strURI.Substring(0, 7); /*string strProtocol = strURI.Substring(0, 7);
if (strProtocol != "http://" if (strProtocol != "http://"
|| ||
strProtocol != "https://") strProtocol != "https://")
return false;*/ return false;*/
if (!strURI.ToLower().StartsWith("http://") || strURI.ToLower().StartsWith("https://")) if (!strURI.ToLower().StartsWith("http://") || strURI.ToLower().StartsWith("https://"))
@ -1109,11 +1109,11 @@ public static class AxiHttp
return (long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds; return (long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds;
} }
/// <summary> /// <summary>
/// 将16进制转换成10进制 /// 将16进制转换成10进制
/// </summary> /// </summary>
/// <param name="str">16进制字符串</param> /// <param name="str">16进制字符串</param>
/// <returns></returns> /// <returns></returns>
public static int convertToIntBy16(String str) public static int convertToIntBy16(String str)
{ {
try try
@ -1145,11 +1145,11 @@ public static class AxiHttp
} }
/// <summary> /// <summary>
/// 将字符串转换成数字错误返回0 /// 将字符串转换成数字错误返回0
/// </summary> /// </summary>
/// <param name="strs">字符串</param> /// <param name="strs">字符串</param>
/// <returns></returns> /// <returns></returns>
public static int convertToInt(String str) public static int convertToInt(String str)
{ {
@ -1231,6 +1231,6 @@ public static class AxiHttp
TimeoutObject.Set(); TimeoutObject.Set();
} }
} }
} }
} }

View File

@ -1,2 +1,11 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 5a498f74133ebfa4fa238a33a1c4c0c3 guid: 5a498f74133ebfa4fa238a33a1c4c0c3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,7 +1,7 @@
using UnityEngine; using UnityEngine;
using static AxiHttp; using static AxiHttp;
public static class AxiHttpProxy public static class AxiHttpProxy
{ {
public static SendWebRequestProxy Get(string url) public static SendWebRequestProxy Get(string url)
{ {
@ -46,7 +46,7 @@ public static class AxiHttpProxy
public static void ShowAxiHttpDebugInfo(AxiRespInfo resp) public static void ShowAxiHttpDebugInfo(AxiRespInfo resp)
{ {
#if UNITY_EDITOR #if UNITY_EDITOR
Debug.Log($""); Debug.Log($"");
Debug.Log($"==== request ===="); Debug.Log($"==== request ====");
Debug.Log($"url =>{resp.url}"); Debug.Log($"url =>{resp.url}");
@ -75,22 +75,22 @@ public static class AxiHttpProxy
{ {
Debug.LogError($"code->{resp.code} err->{resp.ErrInfo} url->{resp.url}"); Debug.LogError($"code->{resp.code} err->{resp.ErrInfo} url->{resp.url}");
} }
#else #else
Debug.Log($"==== request url => { resp.url}"); Debug.Log($"==== request url => { resp.url}");
Debug.Log($"code =>{resp.code}"); Debug.Log($"code =>{resp.code}");
Debug.Log($"respInfo.bTimeOut =>{resp.bTimeOut}"); Debug.Log($"respInfo.bTimeOut =>{resp.bTimeOut}");
Debug.Log($"==== response ===="); Debug.Log($"==== response ====");
if (resp.downloadMode == AxiDownLoadMode.NotDownLoad) if (resp.downloadMode == AxiDownLoadMode.NotDownLoad)
{ {
Debug.Log($"body_text =>{resp.body}"); Debug.Log($"body_text =>{resp.body}");
Debug.Log($"body_text.Length =>{resp.body.Length}"); Debug.Log($"body_text.Length =>{resp.body.Length}");
} }
else else
{ {
Debug.Log($"==== download ===="); Debug.Log($"==== download ====");
Debug.Log($"respInfo.loadedLenght =>{resp.loadedLenght}"); Debug.Log($"respInfo.loadedLenght =>{resp.loadedLenght}");
} }
#endif #endif
//if (resp.downloadMode == AxiDownLoadMode.DownLoadBytes) //if (resp.downloadMode == AxiDownLoadMode.DownLoadBytes)
//{ //{
@ -118,6 +118,6 @@ public static class AxiHttpProxy
// Debug.Log($"DownLoad Err {ex.ToString()}"); // Debug.Log($"DownLoad Err {ex.ToString()}");
// } // }
//} //}
} }
} }

View File

@ -1,2 +1,11 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: ec8e2e405992b234eb08896da0f85317 guid: ec8e2e405992b234eb08896da0f85317
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,51 @@
using System;
using System.Collections;
using UnityEngine;
public class AxiHttpTest : MonoBehaviour
{
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.T))
{
//for (int i = 0; i < 1000; i++)
StartCoroutine(DownloadFromURL("http://emu.axibug.com/UserSav/12/Nes/190/1/1.sav", "D:/1.bin", null));
}
}
IEnumerator DownloadFromURL(string url, string path, Action<byte[]> callback)
{
for (int i = 0; i < 1000; i++)
{
AxiHttpProxy.SendDownLoadProxy request = AxiHttpProxy.GetDownLoad(url);
while (!request.downloadHandler.isDone)
{
Debug.Log($"下载进度:{request.downloadHandler.DownLoadPr} ->{request.downloadHandler.loadedLenght}/{request.downloadHandler.NeedloadedLenght}");
yield return null;
}
AxiHttpProxy.ShowAxiHttpDebugInfo(request.downloadHandler);
Debug.Log($"下载进度完毕:data.Length=>" + request.downloadHandler.data.Length);
}
//if (!request.downloadHandler.bHadErr)
//{
// AxiIO.Directory.CreateDirectory(path);
// AxiIO.File.WriteAllBytes($"{path}/{url.GetHashCode()}", request.downloadHandler.data, false);
// callback?.Invoke(request.downloadHandler.data);
//}
//else
//{
// callback?.Invoke(null);
//}
}
}

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 873427ab0a955e64fa2444505ef0775c