mirror of https://gitee.com/apiumc/Gateway.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.5 KiB
C#
65 lines
1.5 KiB
C#
1 year ago
|
using System.Threading.Tasks;
|
||
|
using System;
|
||
|
using System.IO;
|
||
|
using System.Text;
|
||
|
using UMC.Net;
|
||
|
using System.Net.WebSockets;
|
||
|
|
||
|
namespace UMC.Host
|
||
|
{
|
||
|
|
||
|
class HttpsWebSocket : WebSocket
|
||
|
{
|
||
|
public byte[] buffer = System.Buffers.ArrayPool<byte>.Shared.Rent(0x600);
|
||
|
System.IO.Stream stream;
|
||
|
public HttpsWebSocket(HttpMime mime, System.IO.Stream stream)
|
||
|
{
|
||
|
mime1 = mime;
|
||
|
this.stream = stream;
|
||
|
WebSocketRead();
|
||
|
}
|
||
|
public override void Receive(byte[] buffer, int offset, int size)
|
||
|
{
|
||
|
stream.Write(buffer, offset, size);
|
||
|
|
||
|
}
|
||
|
HttpMime mime1;
|
||
|
async void WebSocketRead()
|
||
|
{
|
||
|
int size = 0;
|
||
|
try
|
||
|
{
|
||
|
while ((size = await stream.ReadAsync(buffer, 0, buffer.Length)) > 0)
|
||
|
{
|
||
|
mime1.Write(buffer, 0, size);
|
||
|
}
|
||
|
}
|
||
|
catch
|
||
|
{
|
||
|
this.Dispose();
|
||
|
return;
|
||
|
}
|
||
|
this.Dispose();
|
||
|
}
|
||
|
|
||
|
|
||
|
public override void Dispose()
|
||
|
{
|
||
|
mime1.Dispose();
|
||
|
stream.Close();
|
||
|
stream.Dispose();
|
||
|
if (buffer != null)
|
||
|
{
|
||
|
System.Buffers.ArrayPool<byte>.Shared.Return(buffer);
|
||
|
buffer = null;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
protected override void Header(byte[] data, int offset, int size)
|
||
|
{
|
||
|
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|