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

View File

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

View File

@ -1,2 +1,11 @@
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