This repository has been archived on 2023-10-16. You can view files and clone it, but cannot push or open issues or pull requests.
2022-04-09 22:34:05 +00:00
|
|
|
using System;
|
|
|
|
|
|
|
|
namespace Hamakaze.WebSocket {
|
|
|
|
public class WsBufferedSend : IDisposable {
|
|
|
|
private WsConnection Connection { get; }
|
|
|
|
|
|
|
|
internal WsBufferedSend(WsConnection conn) {
|
|
|
|
Connection = conn ?? throw new ArgumentNullException(nameof(conn));
|
|
|
|
}
|
|
|
|
|
2022-04-10 16:06:56 +00:00
|
|
|
public void SendPart(ReadOnlySpan<byte> data)
|
|
|
|
=> Connection.WriteFrame(WsOpcode.DataBinary, data, false);
|
|
|
|
|
|
|
|
public void SendFinalPart(ReadOnlySpan<byte> data)
|
|
|
|
=> Connection.WriteFrame(WsOpcode.DataBinary, data, true);
|
2022-04-09 22:34:05 +00:00
|
|
|
|
|
|
|
private bool IsDisposed;
|
|
|
|
|
|
|
|
~WsBufferedSend() {
|
|
|
|
DoDispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Dispose() {
|
|
|
|
DoDispose();
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void DoDispose() {
|
|
|
|
if(IsDisposed)
|
|
|
|
return;
|
|
|
|
IsDisposed = true;
|
|
|
|
|
2022-04-10 16:06:56 +00:00
|
|
|
Connection.EndBufferedSend();
|
2022-04-09 22:34:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|