- Initial commit
This commit is contained in:
56
Runtime/Implementations/Utils/LockedBufferSegmenStream.cs
Normal file
56
Runtime/Implementations/Utils/LockedBufferSegmenStream.cs
Normal file
@ -0,0 +1,56 @@
|
||||
#if (!UNITY_WEBGL || UNITY_EDITOR) && !BESTHTTP_DISABLE_ALTERNATE_SSL
|
||||
using Best.HTTP.Shared.PlatformSupport.Memory;
|
||||
using Best.HTTP.Shared.Streams;
|
||||
|
||||
namespace Best.WebSockets.Implementations.Utils
|
||||
{
|
||||
public sealed class LockedBufferSegmenStream : BufferSegmentStream
|
||||
{
|
||||
public bool IsClosed { get; private set; }
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count)
|
||||
{
|
||||
lock (base.bufferList)
|
||||
{
|
||||
if (this.IsClosed && base.bufferList.Count == 0)
|
||||
return 0;
|
||||
|
||||
int sumReadCount = base.Read(buffer, offset, count);
|
||||
|
||||
return sumReadCount == 0 ? -1 : sumReadCount;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Write(BufferSegment bufferSegment)
|
||||
{
|
||||
lock (base.bufferList)
|
||||
{
|
||||
if (this.IsClosed)
|
||||
return;
|
||||
|
||||
base.Write(bufferSegment);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
lock (base.bufferList)
|
||||
{
|
||||
base.Reset();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
|
||||
Reset();
|
||||
}
|
||||
|
||||
public override void Close()
|
||||
{
|
||||
this.IsClosed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bc8a4ee1efb2f884695f2ec1339025e4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 268757
|
||||
packageName: Best WebSockets
|
||||
packageVersion: 3.0.7
|
||||
assetPath: Packages/com.tivadar.best.websockets/Runtime/Implementations/Utils/LockedBufferSegmenStream.cs
|
||||
uploadId: 737284
|
||||
Reference in New Issue
Block a user