Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -333,14 +333,11 @@ internal static int Encrypt(SafeSslHandle context, ReadOnlySpan<byte> input, ref
int retVal;
Exception? innerError = null;

lock (context)
{
retVal = Ssl.SslWrite(context, ref MemoryMarshal.GetReference(input), input.Length);
retVal = Ssl.SslWrite(context, ref MemoryMarshal.GetReference(input), input.Length);

if (retVal != input.Length)
{
errorCode = GetSslError(context, retVal, out innerError);
}
if (retVal != input.Length)
{
errorCode = GetSslError(context, retVal, out innerError);
}

if (retVal != input.Length)
Expand Down Expand Up @@ -390,30 +387,27 @@ internal static int Decrypt(SafeSslHandle context, byte[] outBuffer, int offset,
int retVal = BioWrite(context.InputBio!, outBuffer, offset, count);
Exception? innerError = null;

lock (context)
if (retVal == count)
{
if (retVal == count)
unsafe
{
unsafe
fixed (byte* fixedBuffer = outBuffer)
{
fixed (byte* fixedBuffer = outBuffer)
{
retVal = Ssl.SslRead(context, fixedBuffer + offset, outBuffer.Length);
}
}

if (retVal > 0)
{
count = retVal;
retVal = Ssl.SslRead(context, fixedBuffer + offset, outBuffer.Length);
}
}

if (retVal != count)
if (retVal > 0)
{
errorCode = GetSslError(context, retVal, out innerError);
count = retVal;
}
}

if (retVal != count)
{
errorCode = GetSslError(context, retVal, out innerError);
}

if (retVal != count)
{
retVal = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ public partial class SslStream
private interface ISslIOAdapter
{
ValueTask<int> ReadAsync(Memory<byte> buffer);
ValueTask<int> ReadLockAsync(Memory<byte> buffer);
Task WriteLockAsync();
ValueTask WriteAsync(byte[] buffer, int offset, int count);
CancellationToken CancellationToken { get; }
}
Expand All @@ -31,10 +29,6 @@ public AsyncSslIOAdapter(SslStream sslStream, CancellationToken cancellationToke

public ValueTask<int> ReadAsync(Memory<byte> buffer) => _sslStream.InnerStream.ReadAsync(buffer, _cancellationToken);

public ValueTask<int> ReadLockAsync(Memory<byte> buffer) => _sslStream.CheckEnqueueReadAsync(buffer);

public Task WriteLockAsync() => _sslStream.CheckEnqueueWriteAsync();

public ValueTask WriteAsync(byte[] buffer, int offset, int count) => _sslStream.InnerStream.WriteAsync(new ReadOnlyMemory<byte>(buffer, offset, count), _cancellationToken);

public CancellationToken CancellationToken => _cancellationToken;
Expand All @@ -48,20 +42,12 @@ public AsyncSslIOAdapter(SslStream sslStream, CancellationToken cancellationToke

public ValueTask<int> ReadAsync(Memory<byte> buffer) => new ValueTask<int>(_sslStream.InnerStream.Read(buffer.Span));

public ValueTask<int> ReadLockAsync(Memory<byte> buffer) => new ValueTask<int>(_sslStream.CheckEnqueueRead(buffer));

public ValueTask WriteAsync(byte[] buffer, int offset, int count)
{
_sslStream.InnerStream.Write(buffer, offset, count);
return default;
}

public Task WriteLockAsync()
{
_sslStream.CheckEnqueueWrite();
return Task.CompletedTask;
}

public CancellationToken CancellationToken => default;
}
}
Expand Down
Loading