private void InternalBeginWrite(InternalAsyncResult asyncResult)
{
byte[] new_buffer = asyncResult.Buffer;
if (asyncResult.Offset != 0 && asyncResult.Count != 0)
{
new_buffer = new byte[asyncResult.Count];
Array.Copy(asyncResult.Buffer, asyncResult.Offset, new_buffer, 0, asyncResult.Count);
}
// Only write to the SSL object if we have data
if (asyncResult.Count != 0)
{
int bytesWritten = ssl.Write(new_buffer, asyncResult.Count);
if (bytesWritten < 0)
{
SslError lastError = ssl.GetError(bytesWritten);
if (lastError == SslError.SSL_ERROR_WANT_READ)
{
//!!TODO - Log - unexpected renogiation request
}
throw new OpenSslException();
}
}
uint bytesPending = write_bio.BytesPending;
//!!while (bytesPending > 0)
{
if( bytesPending > 0)
{
ArraySegment<byte> buf = write_bio.ReadBytes((int)bytesPending);
innerStream.BeginWrite(buf.Array, 0, buf.Count, new AsyncCallback(InternalWriteCallback), asyncResult);
}
else
innerStream.BeginWrite(new byte[0], 0, 0, new AsyncCallback(InternalWriteCallback), asyncResult);
//!!bytesPending = write_bio.BytesPending;
}
}