Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ ReadAsyncInternal< TIOAdapter >()

async ValueTask< int > System.Net.Security.SslStream.ReadAsyncInternal< TIOAdapter > ( TIOAdapter adapter,
Memory< byte > buffer )
inlineprivate
Type Constraints
TIOAdapter :IReadWriteAdapter 

Definition at line 1547 of file SslStream.cs.

1547 : IReadWriteAdapter
1548 {
1549 if (Interlocked.Exchange(ref _nestedRead, 1) == 1)
1550 {
1551 throw new NotSupportedException(System.SR.Format(System.SR.net_io_invalidnestedcall, "ReadAsync", "read"));
1552 }
1554 int processedLength = 0;
1555 int frameSize = 0;
1556 try
1557 {
1558 if (_decryptedBytesCount != 0)
1559 {
1560 processedLength = CopyDecryptedData(buffer);
1561 if (processedLength == buffer.Length || !HaveFullTlsFrame(out frameSize))
1562 {
1563 return processedLength;
1564 }
1565 buffer = buffer.Slice(processedLength);
1566 }
1567 if (_receivedEOF)
1568 {
1569 return 0;
1570 }
1571 if (buffer.Length == 0 && _internalBuffer == null)
1572 {
1573 await adapter.ReadAsync(Memory<byte>.Empty).ConfigureAwait(continueOnCapturedContext: false);
1574 }
1575 while (true)
1576 {
1577 frameSize = await EnsureFullTlsFrameAsync(adapter).ConfigureAwait(continueOnCapturedContext: false);
1578 if (frameSize == 0)
1579 {
1580 _receivedEOF = true;
1581 break;
1582 }
1583 SecurityStatusPal securityStatusPal = DecryptData(frameSize);
1584 if (securityStatusPal.ErrorCode != SecurityStatusPalErrorCode.OK)
1585 {
1586 byte[] array = null;
1587 if (_decryptedBytesCount != 0)
1588 {
1589 array = new byte[_decryptedBytesCount];
1592 }
1593 if (System.Net.NetEventSource.Log.IsEnabled())
1594 {
1595 System.Net.NetEventSource.Info(null, $"***Processing an error Status = {securityStatusPal}", "ReadAsyncInternal");
1596 }
1597 if (securityStatusPal.ErrorCode == SecurityStatusPalErrorCode.Renegotiate)
1598 {
1599 if (_handshakeWaiter == null)
1600 {
1602 }
1603 await ReplyOnReAuthenticationAsync(adapter, array).ConfigureAwait(continueOnCapturedContext: false);
1604 continue;
1605 }
1606 if (securityStatusPal.ErrorCode == SecurityStatusPalErrorCode.ContextExpired)
1607 {
1608 _receivedEOF = true;
1609 break;
1610 }
1611 throw new IOException(System.SR.net_io_decrypt, SslStreamPal.GetException(securityStatusPal));
1612 }
1613 if (_decryptedBytesCount > 0)
1614 {
1615 int num = CopyDecryptedData(buffer);
1616 processedLength += num;
1617 if (num == buffer.Length)
1618 {
1619 break;
1620 }
1621 buffer = buffer.Slice(num);
1622 }
1623 if (processedLength != 0)
1624 {
1625 if (!HaveFullTlsFrame(out frameSize))
1626 {
1627 break;
1628 }
1629 TlsFrameHelper.TryGetFrameHeader(_internalBuffer.AsSpan(_internalOffset), ref _lastFrame.Header);
1630 if (_lastFrame.Header.Type != TlsContentType.AppData)
1631 {
1632 break;
1633 }
1634 }
1635 }
1636 return processedLength;
1637 }
1638 catch (Exception ex)
1639 {
1640 if (ex is IOException || (ex is OperationCanceledException && adapter.CancellationToken.IsCancellationRequested))
1641 {
1642 throw;
1643 }
1644 throw new IOException(System.SR.net_io_read, ex);
1645 }
1646 finally
1647 {
1649 _nestedRead = 0;
1650 }
1651 }
static readonly System.Net.NetEventSource Log
static void Info(object thisOrContextObject, FormattableString formattableString=null, [CallerMemberName] string memberName=null)
SecurityStatusPal DecryptData(int frameSize)
TlsFrameHelper.TlsFrameInfo _lastFrame
Definition SslStream.cs:70
volatile TaskCompletionSource< bool > _handshakeWaiter
Definition SslStream.cs:72
bool HaveFullTlsFrame(out int frameSize)
int CopyDecryptedData(Memory< byte > buffer)
static string net_io_invalidnestedcall
Definition SR.cs:24
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string net_io_read
Definition SR.cs:36
static string net_io_decrypt
Definition SR.cs:34
static string net_ssl_io_renego
Definition SR.cs:44
Definition SR.cs:7
static int Exchange(ref int location1, int value)

References System.Net.Security.SslStream._decryptedBytesCount, System.Net.Security.SslStream._decryptedBytesOffset, System.Net.Security.SslStream._handshakeWaiter, System.Net.Security.SslStream._internalBuffer, System.Net.Security.SslStream._internalOffset, System.Net.Security.SslStream._lastFrame, System.Net.Security.SslStream._nestedRead, System.Net.Security.SslStream._receivedEOF, System.array, System.Buffer.BlockCopy(), System.buffer, System.OperationCanceledException.CancellationToken, System.Net.Security.SslStream.CopyDecryptedData(), System.Net.Security.SslStream.DecryptData(), System.Net.SecurityStatusPal.ErrorCode, System.Threading.Interlocked.Exchange(), System.SR.Format(), System.Net.Security.SslStreamPal.GetException(), System.Net.Security.SslStream.HaveFullTlsFrame(), System.Net.NetEventSource.Info(), System.Threading.CancellationToken.IsCancellationRequested, System.Net.NetEventSource.Log, System.SR.net_io_decrypt, System.SR.net_io_invalidnestedcall, System.SR.net_io_read, System.SR.net_ssl_io_renego, System.Net.Security.SslStream.ReturnReadBufferIfEmpty(), System.Net.Security.SslStream.ThrowIfExceptionalOrNotAuthenticated(), and System.Net.Security.TlsFrameHelper.TryGetFrameHeader().