public override int Read(byte[] buffer, int offset, int count) { IntPtr buf = Marshal.AllocHGlobal(count); int readCount; do { readCount = OpenSSL.BIO_read(bio, buf, count); } while (readCount <= 0 && OpenSSL.BIO_should_retry(bio)); OpenSSL.OpenSSLCheck(readCount > 0, "BIO_write"); Marshal.Copy(buf, buffer, offset, readCount); Marshal.FreeHGlobal(buf); return(readCount); }