Beispiel #1
0
        SslStatus NativeReadCallback(IntPtr data, ref nint dataLength)
        {
            if (closed || disposed || parent == null)
            {
                return(SslStatus.ClosedAbort);
            }

            var len        = (int)dataLength;
            var readBuffer = new byte [len];

            Debug("NativeReadCallback: {0} {1}", dataLength, len);

            bool wantMore;
            var  ret = parent.InternalRead(readBuffer, 0, len, out wantMore);

            dataLength = ret;

            Debug("NativeReadCallback #1: {0} - {1} {2}", len, ret, wantMore);

            if (ret < 0)
            {
                return(SslStatus.ClosedAbort);
            }

            Marshal.Copy(readBuffer, 0, data, ret);

            if (ret > 0)
            {
                return(SslStatus.Success);
            }
            else if (wantMore)
            {
                return(SslStatus.WouldBlock);
            }
            else if (ret == 0)
            {
                closedGraceful = true;
                return(SslStatus.ClosedGraceful);
            }
            else
            {
                return(SslStatus.Success);
            }
        }
        SslStatus NativeReadCallback(IntPtr data, ref nint dataLength)
        {
            if (closed || disposed || parent == null)
            {
                return(SslStatus.ClosedAbort);
            }

            // SSL state prevents multiple simultaneous reads (internal MAC would break)
            // so it's possible to reuse a single buffer (not re-allocate one each time)
            var len            = (int)System.Math.Min(dataLength, readBuffer.Length);
            var originalLength = (int)dataLength;

            bool wantMore;
            var  ret = parent.InternalRead(readBuffer, 0, len, out wantMore);

            dataLength = ret;

            if (ret < 0)
            {
                return(SslStatus.ClosedAbort);
            }

            Marshal.Copy(readBuffer, 0, data, ret);

            if (wantMore || len < originalLength)
            {
                return(SslStatus.WouldBlock);
            }
            else if (ret == 0)
            {
                closedGraceful = true;
                return(SslStatus.ClosedGraceful);
            }
            else
            {
                return(SslStatus.Success);
            }
        }